donwload a file from the web with smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

donwload a file from the web with smalltalk

Sylvain pralon

Hi,

 

I just want to know if somebody as already donwload a file from the web, a pdf by example.

I tried with HTTPClient class but I can not do either a stream binary reading nor a writing.

The FTPClient class is not adapted to my problem because I use the http protocol.

Please help me.

 

Thanks in advance

 

sylvain

Reply | Threaded
Open this post in threaded view
|

RE: donwload a file from the web with smalltalk

Steven Kelly

Try something like this:

                | resource stream pdf |

                uri := 'http://www.metacase.com/papers/MetaEditPlus.pdf' asURI.

                resource := uri resource.

                stream := resource stream.

                stream binary.

                [pdf := stream contents] ensure: [stream close].

                ^pdf

 

HTH,

Steve

 

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent: Thursday, April 12, 2007 11:09 AM
To: [hidden email]
Subject: donwload a file from the web with smalltalk

 

Hi,

 

I just want to know if somebody as already donwload a file from the web, a pdf by example.

I tried with HTTPClient class but I can not do either a stream binary reading nor a writing.

The FTPClient class is not adapted to my problem because I use the http protocol.

Please help me.

 

Thanks in advance

 

sylvain

Reply | Threaded
Open this post in threaded view
|

RE: donwload a file from the web with smalltalk

Steven Kelly
In reply to this post by Sylvain pralon

You were close! Note what your code does in the cascade:

out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.

That's equivalent to:

filename :=  'test.pdf' asFilename.

filename withEncoding: #binary.

out := filename writeStream.

 

In other words, the receiver of #writeStream is not the file wrapped in  something that will make it binary (a FileEncodedStreamConstructor), but the plain filename. Sending #writeStream to that will give you a character-based stream with the platform default encoding. What you want is:

 

out := ('test2.pdf' asFilename withEncoding:#binary) writeStream.

 

I'm old fashioned, so I write:

out := 'test2.pdf' asFilename writeStream.

out binary.

 

Steve

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent:
Thursday, April 12, 2007 12:10 PM
To: Steven Kelly
Subject: RE: donwload a file from the web with smalltalk

 

Great it works, but one more question …

I do not find the way to put the returned pdf value into another local writestream.

It seems i had to convert the local writestream into a binary one ?

 

I try something like that :

 

out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.

                 [ out nextPutAll: pdf ] ensure:[ out close ].

 

I have an error which said that I can store only string characters into a stream ?

 

Any idea ?

 

Thanks Steven

 

Sylvain

 

 

De : Steven Kelly [mailto:[hidden email]]
Envoyé : jeudi 12 avril 2007 10:26
À : Sylvain Pralon; [hidden email]
Objet : RE: donwload a file from the web with smalltalk

 

Try something like this:

                | resource stream pdf |

                uri := 'http://www.metacase.com/papers/MetaEditPlus.pdf' asURI.

                resource := uri resource.

                stream := resource stream.

                stream binary.

                [pdf := stream contents] ensure: [stream close].

                ^pdf

 

HTH,

Steve

 

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent:
Thursday, April 12, 2007 11:09 AM
To: [hidden email]
Subject: donwload a file from the web with smalltalk

 

Hi,

 

I just want to know if somebody as already donwload a file from the web, a pdf by example.

I tried with HTTPClient class but I can not do either a stream binary reading nor a writing.

The FTPClient class is not adapted to my problem because I use the http protocol.

Please help me.

 

Thanks in advance

 

sylvain

Reply | Threaded
Open this post in threaded view
|

RE: donwload a file from the web with smalltalk

Steven Kelly
In reply to this post by Sylvain pralon

Better to send follow-ons to the whole list, that way more people can help you (good for you), and the load can be shared (good for me!) :-). You can also try searching the archives of this list or comp.lang.smalltalk with Google, or of this list with http://www.parcplace.net/lists/vwnc-archive

 

Twoflower has a relaxed parser, but is pretty old. James Robertson's BottomFeeder allows to use the external LibTidy library, which seems to work fast and well.

 

HTH,

Steve

 

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent:
Thursday, April 12, 2007 12:41 PM
To: Steven Kelly
Subject: RE: donwload a file from the web with smalltalk

 

Ok thanks it is an beginner mistake lol, so easy to make it that you don’t see it !

Thanks a lot Steven

 

By chance, you maybe know a parcel which can parse some html.

I tried with an xmlparser but even the google page is not xhtml valid, the meta tags are not close.

Maybe the xml parser is a little too strict…

 

Ideas ?

 

sylvain

 

De : Steven Kelly [mailto:[hidden email]]
Envoyé : jeudi 12 avril 2007 11:22
À : Sylvain Pralon; [hidden email]
Objet : RE: donwload a file from the web with smalltalk

 

You were close! Note what your code does in the cascade:

out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.

That's equivalent to:

filename :=  'test.pdf' asFilename.

filename withEncoding: #binary.

out := filename writeStream.

 

In other words, the receiver of #writeStream is not the file wrapped in  something that will make it binary (a FileEncodedStreamConstructor), but the plain filename. Sending #writeStream to that will give you a character-based stream with the platform default encoding. What you want is:

 

out := ('test2.pdf' asFilename withEncoding:#binary) writeStream.

 

I'm old fashioned, so I write:

out := 'test2.pdf' asFilename writeStream.

out binary.

 

Steve

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent:
Thursday, April 12, 2007 12:10 PM
To: Steven Kelly
Subject: RE: donwload a file from the web with smalltalk

 

Great it works, but one more question …

I do not find the way to put the returned pdf value into another local writestream.

It seems i had to convert the local writestream into a binary one ?

 

I try something like that :

 

out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.

                 [ out nextPutAll: pdf ] ensure:[ out close ].

 

I have an error which said that I can store only string characters into a stream ?

 

Any idea ?

 

Thanks Steven

 

Sylvain

 

 

De : Steven Kelly [mailto:[hidden email]]
Envoyé : jeudi 12 avril 2007 10:26
À : Sylvain Pralon; [hidden email]
Objet : RE: donwload a file from the web with smalltalk

 

Try something like this:

                | resource stream pdf |

                uri := 'http://www.metacase.com/papers/MetaEditPlus.pdf' asURI.

                resource := uri resource.

                stream := resource stream.

                stream binary.

                [pdf := stream contents] ensure: [stream close].

                ^pdf

 

HTH,

Steve

 

-----Original Message-----
From: Sylvain Pralon [mailto:[hidden email]]
Sent:
Thursday, April 12, 2007 11:09 AM
To: [hidden email]
Subject: donwload a file from the web with smalltalk

 

Hi,

 

I just want to know if somebody as already donwload a file from the web, a pdf by example.

I tried with HTTPClient class but I can not do either a stream binary reading nor a writing.

The FTPClient class is not adapted to my problem because I use the http protocol.

Please help me.

 

Thanks in advance

 

sylvain

Reply | Threaded
Open this post in threaded view
|

Re: donwload a file from the web with smalltalk

Mark Pirogovsky-3
In reply to this post by Steven Kelly
hello everybody:

What works for me is following code fragment:
aurl := 'http://myhost.co/docs/foo.pdf'.
aFile := 'c:\temp\foo.pdf'

aUrl asURI copyTo: aFile asFilename asURI


To make this work, I also made modifications into the classes:
HttpURL >>
copyFromURI: aURI
        self writeStreamDo:
                        [:dest |
                        | binary |
                        binary := dest isBinary.
                        aURI readStreamDo:
                                        [:src :parms |
                                        [src atEnd] whileFalse:
                                                        [dest extPutAll: (binary ifTrue: [(src nextAvailable: 1024)
asByteArray]
ifFalse: [src nextAvailable: 1024])]]]


FileURL>>
copyFromURI: aURI
        self writeStreamDo:
                        [:dest |
                        | binary |
                        binary := dest isBinary.
                        aURI readStreamDo:
                                        [:src :parms |
                                        [src atEnd] whileFalse:
                                                        [dest nextPutAll: (binary
                                                                                ifTrue: [(src nextAvailable: 1024) asByteArray]
                                                                                ifFalse: [src nextAvailable: 1024])]]]

        "@__markp January 6, 2005 12:06:57 pm"

Net.URI>>
copyFromURI: aURI
        self writeStreamDo:
                        [:dest |
                        aURI readStreamDo:
                                        [:src :parms |
                                        [src atEnd] whileFalse:
                                                        [UI.IncrementNotification raiseSignal.
                                                        dest nextPutAll: (src nextAvailable: 1024)]]]


Hope this helps,

Mark


Steven Kelly wrote:

> You were close! Note what your code does in the cascade:
>
> out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.
>
> That's equivalent to:
>
> filename :=  'test.pdf' asFilename.
>
> filename withEncoding: #binary.
>
> out := filename writeStream.
>
>  
>
> In other words, the receiver of #writeStream is not the file wrapped in
>  something that will make it binary (a FileEncodedStreamConstructor),
> but the plain filename. Sending #writeStream to that will give you a
> character-based stream with the platform default encoding. What you want is:
>
>  
>
> out := ('test2.pdf' asFilename withEncoding:#binary) writeStream.
>
>  
>
> I'm old fashioned, so I write:
>
> out := 'test2.pdf' asFilename writeStream.
>
> out binary.
>
>  
>
> Steve
>
> -----Original Message-----
> From: Sylvain Pralon [mailto:[hidden email]]
> Sent: Thursday, April 12, 2007 12:10 PM
> To: Steven Kelly
> Subject: RE: donwload a file from the web with smalltalk
>
>  
>
> Great it works, but one more question …
>
> I do not find the way to put the returned pdf value into another local
> writestream.
>
> It seems i had to convert the local writestream into a binary one ?
>
>  
>
> I try something like that :
>
>  
>
> out := ( 'test.pdf' asFilename ) withEncoding:#binary; writeStream.
>
>                  [ out nextPutAll: pdf ] ensure:[ out close ].
>
>  
>
> I have an error which said that I can store only string characters into
> a stream ?
>
>  
>
> Any idea ?
>
>  
>
> Thanks Steven
>
>  
>
> Sylvain
>
>  
>
>  
>
> De : Steven Kelly [mailto:[hidden email]]
> Envoyé : jeudi 12 avril 2007 10:26
> À : Sylvain Pralon; [hidden email]
> Objet : RE: donwload a file from the web with smalltalk
>
>  
>
> Try something like this:
>
>                 | resource stream pdf |
>
>                 uri := 'http://www.metacase.com/papers/MetaEditPlus.pdf' 
> asURI.
>
>                 resource := uri resource.
>
>                 stream := resource stream.
>
>                 stream binary.
>
>                 [pdf := stream contents] ensure: [stream close].
>
>                 ^pdf
>
>  
>
> HTH,
>
> Steve
>
>  
>
> -----Original Message-----
> From: Sylvain Pralon [mailto:[hidden email]]
> Sent: Thursday, April 12, 2007 11:09 AM
> To: [hidden email]
> Subject: donwload a file from the web with smalltalk
>
>  
>
> Hi,
>
>  
>
> I just want to know if somebody as already donwload a file from the web,
> a pdf by example.
>
> I tried with HTTPClient class but I can not do either a stream binary
> reading nor a writing.
>
> The FTPClient class is not adapted to my problem because I use the http
> protocol.
>
> Please help me.
>
>  
>
> Thanks in advance
>
>  
>
> sylvain
>