Problems to serialise object when using FileSystem memory

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

Problems to serialise object when using FileSystem memory

Juraj Kubelka-5
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Problems to serialise object when using FileSystem memory

Mariano Martinez Peck
I am quickly answering without testing (I can do that tomorrow otherwise).
Did you see #serializeToByteArray: ? and FLInMemoryBasicSerializationTest? This is not filesytem, but still an in-memory stream.

Also, did you make sure the in memory stream of FileStream is binary and not text? Try sending #binary or so...

Let us know,

On Tue, Sep 1, 2015 at 8:01 PM, Juraj Kubelka <[hidden email]> wrote:
Hi,

I am writing test case that uses following strategy:

-=-=-
| memory file |
memory := FileSystem memory.
file := memory workingDirectory / 'file.fuel'.
FLSerializer serialize: {1. 2. 3} toFileNamed: file.
-=-=-

But it does not work because in StandardFileStream class>> #forceNewFileNamed: a "self fullName: fileName.” is called and it returns a string. So it tries to create the file in the default real file system; not in the memory file system. FLSerializer calls it in:

-=-=-
serialize: anObject toFileNamed: aFilename
        "Serialize the graph starting at the root object received and answers the FLSerialization object"
        StandardFileStream
                forceNewFileNamed: aFilename
                do: [ :aFileStream |
                        aFileStream binary.
                        self serialize: anObject on: aFileStream ]
-=-=-

using a stream neither work:

-=-=-
| disk file |
disk := FileSystem memory.
file := disk workingDirectory / 'file.fuel'.
file writeStreamDo: [ :aStream |
        FLSerializer serialize: {1. 2. 3} on: aStream ].
-=-=-

It produces an improper indexable object.

The only code that works is that one:
-=-=-
| file |
file := FileLocator workingDirectory / 'file.fuel'.
FLSerializer serialize: {1. 2. 3} toFileNamed: file.
-=-=-

I think that using MemoryStore is a clean way to test code that stores contents into a file.
How can I use FLSerializer and MemoryStore together?

Thanks!
Juraj



--
Reply | Threaded
Open this post in threaded view
|

Re: Problems to serialise object when using FileSystem memory

Stephan Eggermont-3
In reply to this post by Juraj Kubelka-5
There is some code missing in the memory filesystem.

MemoryFileSystemEntry has binaryReadStream and readStream, but only
writeStreamDo:

That means that MemoryStore openFileStream:writable doesn't work.

Stephan


Reply | Threaded
Open this post in threaded view
|

Re: Problems to serialise object when using FileSystem memory

Juraj Kubelka-5
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Problems to serialise object when using FileSystem memory

Stephan Eggermont-3
On 02-09-15 19:17, Juraj Kubelka wrote:
> Hi,
>
> I think the main problem is in the StandardFileStream class>>#forceNewFileNamed:do: that converts aFileReference into a string and then it tests if the file exists.
> If this method is correct, then FLSerializer>>serialise:toFileNamed: should not use it.
>
> I have an impression that MemoryStore works well. I can write this:

If you use the parts that are implemented, probably.

Stephan