How do I create a binary stream
Hi I'm checking some of the mooc code in Pharo 70. The Pharo 50/60 version is PNGReadWriter createAFormFrom: 'Sprites.png' asFileReference binaryReadStream upToEnd I came up with PNGReadWriter formFromStream: (File named: 'Sprites.png') readStream And we can also have PNGReadWriter formFromStream: 'Sprites.png' asFileReference binaryReadStream I will add this in the comment of the formFromStream: method. Stef
Hi Stef, On Sun, 11 Nov 2018 at 10:04, Stephane Ducasse <stepharo.self@gmail.com> wrote:
Hi
I'm checking some of the mooc code in Pharo 70.
The Pharo 50/60 version is
PNGReadWriter createAFormFrom: 'Sprites.png' asFileReference binaryReadStream upToEnd
I came up with
PNGReadWriter formFromStream: (File named: 'Sprites.png') readStream
And we can also have
PNGReadWriter formFromStream: 'Sprites.png' asFileReference binaryReadStream
I will add this in the comment of the formFromStream: method.
FileReference is the normal public interface to the file system, while File is a low level API that is only used in limited circumstances, e.g. bootstrapping when FileSystem isn't yet available. Most users shouldn't have to worry about File, so I'd leave it out as an example. Cheers, Alistair
On 11 Nov 2018, at 10:29, Alistair Grant <akgrant0710@gmail.com> wrote:
File is a low level API that is only used in limited circumstances, e.g. bootstrapping when FileSystem isn't yet available.
Another reason not to use File is because it is slower as it is unbuffered. For the following file $ file test.png test.png: PNG image data, 950 x 936, 8-bit/color RGBA, non-interlaced $ ls -la test.png -rw-r--r--@ 1 sven staff 241773 Nov 11 13:39 test.png I get [ ImageReadWriter formFromFileNamed: 'test.png' ] bench. "'8.725 per second'" [ ImageReadWriter formFromStream: 'test.png' asFileReference binaryReadStream ] bench. "'8.914 per second'" [ ImageReadWriter formFromStream: (File named: 'test.png') readStream ] bench. "'6.023 per second'" By preventing the auto detection of the type and the subclass lookup, we can improve a little bit more. [ PNGReadWriter formFromStream: 'test.png' asFileReference binaryReadStream ] bench. "'9.113 per second'" Sven
I met that situation too with P7. It occurred to me that the precise need of #binaryReadStream message vanished. Hilaire Le 11/11/2018 à 10:03, Stephane Ducasse a écrit :
Hi
I'm checking some of the mooc code in Pharo 70.
The Pharo 50/60 version is
PNGReadWriter createAFormFrom: 'Sprites.png' asFileReference binaryReadStream upToEnd
I came up with
PNGReadWriter formFromStream: (File named: 'Sprites.png') readStream
And we can also have
PNGReadWriter formFromStream: 'Sprites.png' asFileReference binaryReadStream
I will add this in the comment of the formFromStream: method.
Stef
-- Dr. Geo http://drgeo.eu
On 11 Nov 2018, at 10:59, Hilaire <hilaire@drgeo.eu> wrote:
I met that situation too with P7. It occurred to me that the precise need of #binaryReadStream message vanished.
I don't understand what you are saying. Like Alistair says, FileReference is the public interface. The messages to open streams are #readStream #writeStream for text streams (utf8 character encoded) and #binaryReadStream #binaryWriteStream for raw unencoded binary streams. In most cases, it is better to use the #xDo: variant. It is no longer possible to switch streams using #binary.
Hilaire
Le 11/11/2018 à 10:03, Stephane Ducasse a écrit :
Hi
I'm checking some of the mooc code in Pharo 70.
The Pharo 50/60 version is
PNGReadWriter createAFormFrom: 'Sprites.png' asFileReference binaryReadStream upToEnd
I came up with
PNGReadWriter formFromStream: (File named: 'Sprites.png') readStream
And we can also have
PNGReadWriter formFromStream: 'Sprites.png' asFileReference binaryReadStream
I will add this in the comment of the formFromStream: method.
Stef
-- Dr. Geo http://drgeo.eu
In P7, I have to change the code to load PNG image, and I end up not using binary alternative... Le 11/11/2018 à 11:18, Sven Van Caekenberghe a écrit :
I don't understand what you are saying.
-- Dr. Geo http://drgeo.eu
So how do you load you PNG's then in P7 ?
On 11 Nov 2018, at 11:25, Hilaire <hilaire@drgeo.eu> wrote:
In P7, I have to change the code to load PNG image, and I end up not using binary alternative...
Le 11/11/2018 à 11:18, Sven Van Caekenberghe a écrit :
I don't understand what you are saying.
-- Dr. Geo http://drgeo.eu
Confusion from my part (it was 6 months ago), I have to use #binaryReadStream to load PNG preview, and utf-8 based file (I was not doing this distinction previously). I changed the code in P7 in several part as it broke and it was confusing. https://bazaar.launchpad.net/~drgeo-developers/drgeo/trunk/revision/608#src/... Le 11/11/2018 à 11:41, Sven Van Caekenberghe a écrit :
So how do you load you PNG's then in P7 ?
-- Dr. Geo http://drgeo.eu
I filled a bug ticket about the change: https://bugs.launchpad.net/drgeo/+bug/1780820 -- Dr. Geo http://drgeo.eu
On 11 Nov 2018, at 12:24, Hilaire <hilaire@drgeo.eu> wrote:
Confusion from my part (it was 6 months ago), I have to use #binaryReadStream to load PNG preview, and utf-8 based file (I was not doing this distinction previously).
I changed the code in P7 in several part as it broke and it was confusing.
API changes are always annoying, but splitting reading and writing as well as binary and character streams is a clear improvement overall.
I am quite happy with the new FileReference API. Le 11/11/2018 à 13:51, Sven Van Caekenberghe a écrit :
API changes are always annoying, but splitting reading and writing as well as binary and character streams is a clear improvement overall.
-- Dr. Geo http://drgeo.eu
Thanks you all for the discussion. We should improve the comment of File and probably the one of FileReference. Tx Sven for the improvement of the comment of ImageReadWriter. Good comments are so important! We underestimate their impact. S On Sun, Nov 11, 2018 at 2:10 PM Hilaire <hilaire@drgeo.eu> wrote:
I am quite happy with the new FileReference API.
Le 11/11/2018 à 13:51, Sven Van Caekenberghe a écrit :
API changes are always annoying, but splitting reading and writing as well as binary and character streams is a clear improvement overall.
-- Dr. Geo http://drgeo.eu
participants (4)
-
Alistair Grant -
Hilaire -
Stephane Ducasse -
Sven Van Caekenberghe