Saving an object
Last updated at 7:15 pm UTC on 12 October 2019
A method in class object so that every object may be saved to a file:
saveOnFileNamed: filenameString
"Save myself on a SmartReferenceStream file. Writes out the version and class structure. The file is fileIn-able. UniClasses will be filed out."
| fileStream |
fileStream := FileStream newFileNamed: filenameString.
fileStream fileOutClass: nil andObject: self. "Puts UniClass definitions out anyway, and closes the stream."
A variant which might be better in some cases.
saveOnFileNamed: aString
"Ask the user for a filename and save myself on a
ReferenceStream file. Writes out the version and class structure.
This saves an object (with other objects held by it) as an .obj file"
| aFileName fileStream |
aString isEmpty
ifTrue: [^ self error: 'name is missing'].
aFileName := aString , '.obj'.
fileStream := ReferenceStream fileNamed: aFileName .
fileStream nextPut: self.
fileStream close.