[Cuis-dev] FileMan and FileStream?

KenD Ken.Dickey at Whidbey.com
Fri Dec 18 18:47:47 CST 2015


On Fri, 18 Dec 2015 19:16:34 -0500
"Phil \(list\) via Cuis-dev" <cuis-dev at cuis-smalltalk.org> wrote:

> One thing I've been scratching my head over is how we should be using
> FileStreams with files now that things have moved over to FileMan.  I
> see things like privateReadStream and they're used all over the image
> but if they're really all private*, should they be?  I.e. should they
> be renamed or is there some sort of public stream API for them in the
> works?

I have been using FileMan code without any reference to privateReadStream.

E.g.:
----
saveAs: aName
	| refStream |
	fileName := self class withExtension: aName.
	self flushUndoRedoCommands.
	fileName asFileEntry forceWriteStream: [ :strm |
		refStream := SmartRefStream on: strm.
		refStream nextPut: self 
	].
----
fromFileNamed: aFileName
	| fileName model |
	fileName := self withExtension: aFileName.
	fileName asFileEntry readStream: [ :strm |
		model := (SmartRefStream on: strm) next
	].
	model fileName: fileName.
	"Crude way to fix old Color subInstances in files"
	"
	Color allInstancesDo: [ :c | c fix ].
	TranslucentColor allInstancesDo: [ :c | c fix ].
	"
	^model
----
saveGame: dotSuffix userMessage: aPromptString
	"Show a file dialog to the user to save a game with dotSuffix (e.g. '*.foo').
	Subclasses save specific data as compressed Deck and CardContainer objects."

	| dialogResult |
	
	dialogResult := (StandardFileMenu new) 
   					newFileFrom: Smalltalk imagePath asDirectoryEntry
					withPattern:  '*.' , dotSuffix; 
					startUpWithCaption: aPromptString.
	
	(dialogResult isNil)
	ifTrue: [ ^nil ]
	ifFalse: [ | filePath |
		filePath := (dialogResult directory // dialogResult name) pathName.
		filePath := self ensureFileName: filePath hasSuffix:  '.', dotSuffix.
		filePath asFileEntry writeStream: [ :file | | aDataStream |
			aDataStream := DataStream on: file. 
			self saveGameToDataStream: aDataStream.
			aDataStream close
		]
	]
----
-KenD



More information about the Cuis-dev mailing list