Sean, On 26 Apr 2012, at 02:23, Sean P. DeNigris wrote:
Sven Van Caekenberghe wrote
Now, you are right that there should be some convenience method to make that easier. I'll think about it for a bit and let you know if I can come up with something.
What about: download: urlString to: anFSReference "anFSReference can be either: - a directory, where the file will be saved under its original name - otherwise, the file will be saved as the FSReference"
| target entity | target := anFSReference isDirectory ifTrue: [ anFSReference / urlString asUrl path last ] ifFalse: [ anFSReference ].
entity := ZnClient new streaming: true; get: urlString; entity. target fileStreamDo: [ :stream | stream binary. entity writeOn: stream ].
This would allow really easy, flexible use like: "Save in this directory as same name" ZnClient download: 'http://www.pharo-project.org/images/pharo.png' to: '/Volumes/Fast/Squeak/Main Working Images/Pharo-1.3' asFile.
"Save under new name in this exact place" ZnClient download: 'http://www.pharo-project.org/images/pharo.png' to: '/Volumes/Fast/Squeak/Main Working Images/Pharo-1.3/new_name.png' asFile.
I implemented ZnClient>>#downloadTo: which accepts both a directory or a filename path string. (Zinc-HTTP-SvenVanCaekenberghe.265 and Zinc-Tests-SvenVanCaekenberghe.136). ZnClient new systemPolicy; accept: ZnMimeType text; url: 'http://zn.stfx.eu/zn/numbers.txt'; downloadTo: '/Users/sven/Desktop'. I temporarily rolled back my use of FileSystem due to http://code.google.com/p/pharo/issues/detail?id=5693 and the fact that I had to hack too much to maintain 1.3 compatibility (you can still see the code in a previous version, Zinc-HTTP-SvenVanCaekenberghe.264). Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill