creating a png filereference in memory

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

creating a png filereference in memory

Tudor Girba-2
Hi,

I have troubles creating a PNG file in memory.

I can create a PNG file on disk and load it back without problems:
f := FileSystem disk workingDirectory / 'pharoicon.png'.
f writeStreamDo: [ :stream |
PNGReadWriter 
putForm: ThemeIcons current pharoIcon 
onStream: stream ].
f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]

But, when I try the same thing in memory, I get an exception for incorrect format:
f := FileSystem memory workingDirectory / 'pharoicon.png'.
f writeStreamDo: [ :stream |
PNGReadWriter 
putForm: ThemeIcons current pharoIcon 
onStream: stream ].
f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]

Can anyone point me to what am I doing wrong?

Doru


--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: creating a png filereference in memory

Sven Van Caekenberghe-2
Doru,

I think you will need the new #binaryReadStream or #binaryReadStreamDo:

Sven

On 02 Feb 2014, at 20:15, Tudor Girba <[hidden email]> wrote:

> Hi,
>
> I have troubles creating a PNG file in memory.
>
> I can create a PNG file on disk and load it back without problems:
> f := FileSystem disk workingDirectory / 'pharoicon.png'.
> f writeStreamDo: [ :stream |
> PNGReadWriter
> putForm: ThemeIcons current pharoIcon
> onStream: stream ].
> f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
>
> But, when I try the same thing in memory, I get an exception for incorrect format:
> f := FileSystem memory workingDirectory / 'pharoicon.png'.
> f writeStreamDo: [ :stream |
> PNGReadWriter
> putForm: ThemeIcons current pharoIcon
> onStream: stream ].
> f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
>
> Can anyone point me to what am I doing wrong?
>
> Doru
>
>
> --
> www.tudorgirba.com
>
> "Every thing has its own flow"


Reply | Threaded
Open this post in threaded view
|

Re: creating a png filereference in memory

Tudor Girba-2
Thanks! That worked.

What is the difference?

Doru




On Sun, Feb 2, 2014 at 9:19 PM, Sven Van Caekenberghe <[hidden email]> wrote:
Doru,

I think you will need the new #binaryReadStream or #binaryReadStreamDo:

Sven

On 02 Feb 2014, at 20:15, Tudor Girba <[hidden email]> wrote:

> Hi,
>
> I have troubles creating a PNG file in memory.
>
> I can create a PNG file on disk and load it back without problems:
> f := FileSystem disk workingDirectory / 'pharoicon.png'.
> f writeStreamDo: [ :stream |
>       PNGReadWriter
>               putForm: ThemeIcons current pharoIcon
>               onStream: stream ].
> f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
>
> But, when I try the same thing in memory, I get an exception for incorrect format:
> f := FileSystem memory workingDirectory / 'pharoicon.png'.
> f writeStreamDo: [ :stream |
>       PNGReadWriter
>               putForm: ThemeIcons current pharoIcon
>               onStream: stream ].
> f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
>
> Can anyone point me to what am I doing wrong?
>
> Doru
>
>
> --
> www.tudorgirba.com
>
> "Every thing has its own flow"





--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: creating a png filereference in memory

Sven Van Caekenberghe-2

On 02 Feb 2014, at 22:13, Tudor Girba <[hidden email]> wrote:

> Thanks! That worked.
>
> What is the difference?

It's a complicated story ;-)

https://pharo.fogbugz.com/f/cases/12259/FileSystem-memory-reads-writes-using-a-binary-stream-by-default

> Doru
>
>
>
>
> On Sun, Feb 2, 2014 at 9:19 PM, Sven Van Caekenberghe <[hidden email]> wrote:
> Doru,
>
> I think you will need the new #binaryReadStream or #binaryReadStreamDo:
>
> Sven
>
> On 02 Feb 2014, at 20:15, Tudor Girba <[hidden email]> wrote:
>
> > Hi,
> >
> > I have troubles creating a PNG file in memory.
> >
> > I can create a PNG file on disk and load it back without problems:
> > f := FileSystem disk workingDirectory / 'pharoicon.png'.
> > f writeStreamDo: [ :stream |
> >       PNGReadWriter
> >               putForm: ThemeIcons current pharoIcon
> >               onStream: stream ].
> > f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
> >
> > But, when I try the same thing in memory, I get an exception for incorrect format:
> > f := FileSystem memory workingDirectory / 'pharoicon.png'.
> > f writeStreamDo: [ :stream |
> >       PNGReadWriter
> >               putForm: ThemeIcons current pharoIcon
> >               onStream: stream ].
> > f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
> >
> > Can anyone point me to what am I doing wrong?
> >
> > Doru
> >
> >
> > --
> > www.tudorgirba.com
> >
> > "Every thing has its own flow"
>
>
>
>
>
> --
> www.tudorgirba.com
>
> "Every thing has its own flow"


Reply | Threaded
Open this post in threaded view
|

Re: creating a png filereference in memory

Tudor Girba-2
I see.

However, I still do not understand two things:
1. Why does it work if I read and write to the file system?

f := FileSystem disk workingDirectory / 'pharoicon.png'.
f writeStreamDo: [ :stream |
PNGReadWriter 
putForm: ThemeIcons current pharoIcon 
onStream: stream ].
f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]


2. Why is binaryReadStreamDo: not equivalent to:
f := FileSystem memory workingDirectory / 'pharoicon.png'.
f writeStreamDo: [ :stream |
PNGReadWriter 
putForm: ThemeIcons current pharoIcon 
onStream: stream ].
f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]

Cheers,
Doru


On Sun, Feb 2, 2014 at 11:23 PM, Sven Van Caekenberghe <[hidden email]> wrote:

On 02 Feb 2014, at 22:13, Tudor Girba <[hidden email]> wrote:

> Thanks! That worked.
>
> What is the difference?

It's a complicated story ;-)

https://pharo.fogbugz.com/f/cases/12259/FileSystem-memory-reads-writes-using-a-binary-stream-by-default

> Doru
>
>
>
>
> On Sun, Feb 2, 2014 at 9:19 PM, Sven Van Caekenberghe <[hidden email]> wrote:
> Doru,
>
> I think you will need the new #binaryReadStream or #binaryReadStreamDo:
>
> Sven
>
> On 02 Feb 2014, at 20:15, Tudor Girba <[hidden email]> wrote:
>
> > Hi,
> >
> > I have troubles creating a PNG file in memory.
> >
> > I can create a PNG file on disk and load it back without problems:
> > f := FileSystem disk workingDirectory / 'pharoicon.png'.
> > f writeStreamDo: [ :stream |
> >       PNGReadWriter
> >               putForm: ThemeIcons current pharoIcon
> >               onStream: stream ].
> > f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
> >
> > But, when I try the same thing in memory, I get an exception for incorrect format:
> > f := FileSystem memory workingDirectory / 'pharoicon.png'.
> > f writeStreamDo: [ :stream |
> >       PNGReadWriter
> >               putForm: ThemeIcons current pharoIcon
> >               onStream: stream ].
> > f readStreamDo: [ :stream | PNGReadWriter formFromStream: stream binary ]
> >
> > Can anyone point me to what am I doing wrong?
> >
> > Doru
> >
> >
> > --
> > www.tudorgirba.com
> >
> > "Every thing has its own flow"
>
>
>
>
>
> --
> www.tudorgirba.com
>
> "Every thing has its own flow"





--

"Every thing has its own flow"