[Glass] Files and UTF8 but not using String #encodeAsUTF8
Mariano Martinez Peck via Glass
glass at lists.gemtalksystems.com
Thu Feb 26 07:03:59 PST 2015
Hi guys,
I am trying to implement the solution provided by Dale for exporting and
importing large objects with SIXX: https://github.com/glassdb/SIXX?files=1
In his example he does:
strm := WriteStream on: String new.
#( 1 2 3) sixxOn: strm persistentRoot: (UserGlobals at:
#'MY_SIXX_ROOT_ARRAY')
That stream 'strm' is in memory. I need files. And I want those files to be
encoded with UTF8. In addition, in my experience, I have been trying to use
GsFile as much as possible since it was way faster than other classes when
I tested it. So...so far I was using the following approach to write a UTF8
file:
file := GsFile openWrite: aFilename.
file nextPutAll: aString encodeAsUTF8.
However, I cannot use that approach in the SIXX scenario. Why? Because I
cannot easily hook in the parts where sixx gets the string of an object and
writes it to the stream. So I kind of need to create the File stream with
UTF8 from the beginning.
I do have UT8TextConverter, but GsFile dnu #converter:. I tried:
| stream |
*stream := MultiByteBinaryOrTextStream on: (GsFile openWrite: aFilename).*
* stream converter: UTF8TextConverter new. *
* stream text. *
MCPlatformSupport commitOnAlmostOutOfMemoryDuring: [
UserGlobals at: #'MY_SIXX_ROOT_ARRAY' put: Array new.
#( 1 2 3) sixxOn: stream persistentRoot: (UserGlobals at:
#'MY_SIXX_ROOT_ARRAY')
].
stream close.
But it doesn't work. Ok..I did see GsFile >> contentsAsUtf8 so I could
write all the file first, then grab the contents as UT8 and then do what I
did above (a new file doing #nextPutAll: of the UTF8). But...since I am
doing all this code because the object graph I am trying to serialize is
big I am afraid I will run out of memory while trying to have all the
contents as UTF8. So I would really like the "streaming" possibility.
Any ideas how can I do that?
Thanks,
--
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20150226/9ca0b6fb/attachment.html>
More information about the Glass
mailing list