Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
DataStream
Last updated at 6:34 pm UTC on 14 October 2019
 DataStream subclasses  
     {ReferenceStream}

Adapted from class comment (Squeak 5.1)
This is the save-to-disk facility. A DataStream can store one or more objects in a persistent form.

To handle objects with sharing and cycles, you must use a
ReferenceStream (or SmartRefStream) instead of a DataStream.

ReferenceStream is typically faster than DataStream and produces smaller files because it doesn't repeatedly write the same Symbols.

Here is the way to use DataStream or a ReferenceStream:
	ds := DataStream fileNamed: 'test.obj'.
	ds nextPut: <your object>.
	ds close.
or
	rs := ReferenceStream fileNamed: 'test.obj'.
	rs nextPut: <your object>.
	rs close.

To get it back:
	ds := DataStream fileNamed: 'test.obj'.
	<your object> := ds next.
	ds close.
or
	rs := ReferenceStream fileNamed: 'test.obj'.
	<your object> := rs next.
	rs close.

Each object to be stored has two opportunities to control what gets stored. On the high level, objectToStoreOnDataStream allows you to substitute another object on the way out. The low level hook is storeDataOn:. The read-in counterparts to these messages are comeFullyUpOnReload and (class) readDataFrom:size:. See these methods, and the class DiskProxy, for more information about externalizing and internalizing.

NOTE: A DataStream should be treated as a write-stream for writing. It is a read-stream for reading. It is not a ReadWriteStream.

DataStream example
DataStream performance example
DataStream example in Cuis

See also

binary object serializer