theseion / Fuel

Fuel, the Smalltalk object serializer
https://theseion.github.io/Fuel
MIT License
26 stars 12 forks source link

Examples of new API? And possible bug... #256

Closed seandenigris closed 2 years ago

seandenigris commented 2 years ago

Not sure what the canonical way to serialize/materialize is in v.4. I tried:

FLSerializer new
        object: anObject;
        fileName: aFileReference withoutExtension fullName;
        fileExtension: aFileReference extension;
        serialize.

But got DNU fileExtension: in spite of the following:

FLConfiguration>>#fileName: aString
    "...
    The filename should be passed without any extension, which can be specified separately
    via #fileExtension:..."

I should mention that I need to control the extension for SimplePersistence, which tracks versions via numbered extensions

theseion commented 2 years ago

Thanks @seandenigris. That comment isn't accurate anymore. I had planned it that way at one point but then changed the implementation. #fileName: really takes the path to a file (as string), including extension.

You can either use fileName: (which is just a convenience method) or pass a block to #streamFactory:, which might give you the flexibility you need. For example:

string := String new: 3.
serializer := FLSerializer new
    streamFactory: [ string writeStream ];
    decorateStreamFactory: [ :stream | byteConverterStream on: stream ];
    yourself.

If your stream is special (e.g. when you use a decorated stream as above), you might also have to override the default stream finalizer:

serializer streamFinalizer: [ :stream | stream doSomething; close ]

I will fix the comment in #fileName: and maybe rename it to #filePathString: since that is more accurate.

seandenigris commented 2 years ago

Ah, okay, I think fileName: will suffice now that I know I can set the extension there. Will give it a try...

seandenigris commented 2 years ago

Yes, it works. Do you want me to leave it open to bookmark the changes/explanation you proposed? Is the explanation in the docs already or should we add it somewhere?

theseion commented 2 years ago

Yes, leave it open. I haven't put any of the 4.0 changes into the docs yet.

theseion commented 2 years ago

In 4.1.0