3

I am using PharoCloud to host a Pharo image for me. By default it downloads a ZIP of the image only to my appliance; this ZIP doesn't include the .sources file.

I am trying to manually download the sources file with ZnClient. The directory my image is located in is /mnt/upload/upload.140605183221.

This is the code I have

| aFileStream |
    aFileStream := '/mnt/universe/upload/upload.140605183221/PharoV30.sources' asFileName writeStream.
    aFileStream write: (ZnClient new get: 'http://files.pharo.org/sources/PharoV30.sources.zip').
    aFileStream close.

I'm brand new to ZnClient; I don't know how to use it. What's wrong with my code?

xofz
  • 5,600
  • 6
  • 45
  • 63

2 Answers2

2

Nearly right. You need to replace the message #asFileName with #asFileReference, since #asFileName will answer a string object (so you actually get a WriteStream on the string).

fileReference := '/mnt/universe/upload/upload.140605183221/PharoV30.sources' asFileReference
fileReference writeStreamDo: [ :stream |
    | url|
    url := 'http://files.pharo.org/sources/PharoV30.sources.zip'.
    stream write: (ZnClient new get: url) ]
Max Leske
  • 5,007
  • 6
  • 42
  • 54
  • Thanks for the info! Getting some context and explanation for why my code won't work really helps and prepares me for future uses of ZnClient. – xofz Jun 12 '14 at 16:26
2

You can do this:

'./PharoV30.sources' asFileReference 
    writeStreamDo: [ :stream | 
        stream write: (ZnClient new get: 'http://files.pharo.org/sources/PharoV30.sources') contents ].
EstebanLM
  • 4,252
  • 14
  • 17
  • Worked perfectly after I changed `ZnConstants maximumEntititySize`. Thanks! – xofz Jun 12 '14 at 16:24
  • 1
    Sending #contents will use a lot of memory space that is only used to write to a file. Instead, you can use `ZnClient>>downloadTo:`. – Damien Cassou Jun 19 '14 at 13:00