[Cuis-dev] FileMan and FileStream?

Phil (list) pbpublist at gmail.com
Fri Dec 18 18:55:57 CST 2015


On Fri, 2015-12-18 at 19:51 -0500, Phil (list) wrote:
> On Fri, 2015-12-18 at 16:47 -0800, KenD wrote:
> > 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.
> > 
> 
> Doh! There they are... right below the private* methods... I need to
> get my eyes checked.  Thanks!
> 

OK, now I remember the issue with that: I don't want to pass a block
in, I need to get the read/write stream back.  I have lots of code that
is stream based and doesn't know or care if its dealing with a file, it
just expects a stream for input/output.

> > 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
> > 		]
> > 	]
> > ----



More information about the Cuis-dev mailing list