5
 TabularResources testExcelSheet

from this project gives me a binary representation in a literal array of an Excel file.

````

testExcelSheet

^ #[80 75 3 4 20 0 6 0 8 0 0 0 33 0 199 122 151 144 120 1 0 0 32 6 0 0 19 0 8 2 91 67 111 110 116 101 110 116 95 84 121 112 101 115 93 46 120 109 108 32 162 4 2 40 160 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .....

....0 109 108 80 75 1 2 45 0 20 0 6 0 8 0 0 0 33 0 126 148 213 45 209 1 0 0 250 10 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 233 36 0 0 120 108 47 99 97 108 99 67 104 97 105 110 46 120 109 108 80 75 5 6 0 0 0 0 13 0 13 0 74 3 0 0 232 38 0 0 0 0]

````

Question

How do I write this to the disk to see which kind of file it is?

Answer

(by Esteban, edited)

./TabularATest1.xlsx' asFileReference writeStreamDo: [ :stream | stream binary; nextPutAll: self testExcelSheet ]

1 Answer 1

10

Easiest way to do that is something like this:

'./file.bin' asFileReference writeStreamDo: [ :stream | 
    stream 
        binary; 
        nextPutAll: #[1 2 3 4 5 6 7 8 9 0] ]

So the trick is just telling to the stream "be a binary file" :)

3
  • Note that there is a compatibility issue at the moment which requires you to use #binaryReadStream et. al if you want to read binary data.
    – Max Leske
    Commented Aug 11, 2015 at 9:23
  • @MaxLeske -- could you please elaborate a bit? I added a code snippet based on EstebanLM's answer and it worked.
    – z--
    Commented Aug 11, 2015 at 11:13
  • 1
    For clarification: I was talking about reading binary data. The way that read streams are constructed at the moment does not allow switching from ascii to binary mode. Instead, you should use #binaryReadStream et. al to get a binary readstream. If you don't do that, you may experience some weird things happening to your data. The plan is to get rid of those extra messages ASAP, but for the moment they are there.
    – Max Leske
    Commented Aug 11, 2015 at 12:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.