Problems to serialise object when using FileSystem memory
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
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 <juraj.kubelka@gmail.com> 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
-- Mariano http://marianopeck.wordpress.com
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
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: -=-=- | disk file | disk := FileSystem memory. file := disk workingDirectory / 'file.fuel'. file writeStreamDo: [ :aStream | aStream nextPutAll: 'hi' ]. [file contents = 'hi'] assert. -=-=- What do you think? Cheers, Juraj
On Sep 2, 2015, at 05:51, Stephan Eggermont <stephan@stack.nl> wrote:
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
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
participants (3)
-
Juraj Kubelka -
Mariano Martinez Peck -
Stephan Eggermont