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 8:52 pm UTC on 22 October 2017
 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 instead of a DataStream. (Or SmartRefStream) ReferenceStream is typically
faster and produces smaller files because it doesn't repeatedly write the same Symbols.

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

To get it back:
	ds := DataStream fileNamed: 'test.obj'.
	<your object> := ds next.
	ds 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 performance example
DataStream example in Cuis