[Pkg] The Trunk: Files-eem.136.mcz

commits at source.squeak.org commits at source.squeak.org
Tue May 27 18:47:33 UTC 2014


Eliot Miranda uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-eem.136.mcz

==================== Summary ====================

Name: Files-eem.136
Author: eem
Time: 27 May 2014, 11:47:15.952 am
UUID: 83fc1540-4b6b-4ff7-b18d-e864e9e7fb16
Ancestors: Files-eem.135

Fix the regression introduced in Files-eem.133 by
implementing peekLast more directly.  Add a lastWritten
inst var to StandardFileStream.  Change the definition of
isBinary so that e.g. WideString could be used as a buffer1
and the file is still considered not binary.

=============== Diff against Files-eem.135 ===============

Item was changed:
  FileStream subclass: #StandardFileStream
+ 	instanceVariableNames: 'name fileID buffer1 lastWritten'
- 	instanceVariableNames: 'name fileID buffer1'
  	classVariableNames: 'Registry'
  	poolDictionaries: ''
  	category: 'Files-Kernel'!
  
  !StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
  Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only.  2/12/96 sw
  
  I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
  	collection	<ByteString> or <ByteArray>	This is the buffer.
  	position	<Integer>	The relative position in the buffer. Greater or equal to zero.
  	readLimit	<Integer>	The number of bytes buffered. Greater or equal to zero.
  Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
  The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
  The buffer state is valid if and only if collection is not nil and position < readLimit.!

Item was changed:
  ----- Method: StandardFileStream>>ascii (in category 'properties-setting') -----
  ascii
  	"opposite of binary"
+ 	buffer1 := ByteString new: 1.
+ 	collection ifNotNil: [collection := collection asString].
+ 	lastWritten ifNotNil: [lastWritten isInteger ifTrue: [lastWritten := lastWritten asCharacter]]!
- 	buffer1 := String new: 1.
- 	collection ifNotNil: [ collection := collection asString ]!

Item was changed:
  ----- Method: StandardFileStream>>binary (in category 'properties-setting') -----
  binary
  	buffer1 := ByteArray new: 1.
+ 	collection ifNotNil: [collection := collection asByteArray].
+ 	lastWritten ifNotNil: [lastWritten isCharacter ifTrue: [lastWritten := lastWritten asInteger]]!
- 	collection ifNotNil: [ collection := collection asByteArray ]!

Item was changed:
  ----- Method: StandardFileStream>>isBinary (in category 'properties-setting') -----
  isBinary
+ 	^buffer1 isString not!
- 	^ buffer1 class == ByteArray!

Item was changed:
  ----- Method: StandardFileStream>>nextPut: (in category 'read, write, position') -----
+ nextPut: element
+ 	"Write the given element (character or integer) to this file."
- nextPut: char
- 	"Write the given character to this file."
  
  	rwmode ifFalse: [^ self error: 'Cannot write a read-only file'].
+ 	collection ifNotNil:
+ 		[position < readLimit ifTrue: [ self flushReadBuffer ] ].
+ 	buffer1 at: 1 put: element.
- 	collection ifNotNil: [ 
- 		position < readLimit ifTrue: [ self flushReadBuffer ] ].
- 	buffer1 at: 1 put: char.
  	self primWrite: fileID from: buffer1 startingAt: 1 count: 1.
+ 	lastWritten := element.
+ 	^ element
- 	^ char
  !

Item was changed:
  ----- Method: StandardFileStream>>nextPutAll: (in category 'read, write, position') -----
+ nextPutAll: aCollection
+ 	"Write all the elements of the given collection (a String or IntegerArray of some kind) to this file."
- nextPutAll: aString
- 	"Write all the characters of the given string to this file."
  	| size |
  	rwmode ifFalse: [^ self error: 'Cannot write a read-only file'].
+ 	collection ifNotNil:
+ 		[position < readLimit ifTrue: [ self flushReadBuffer]].
+ 	(size := aCollection basicSize) > 0 ifTrue:
+ 		[self primWrite: fileID from: aCollection startingAt: 1 count: size.
+ 		 lastWritten := aCollection at: size].
+ 	^ aCollection!
- 	collection ifNotNil: [ 
- 		position < readLimit ifTrue: [ self flushReadBuffer ] ].
- 	(size := aString size) > 0 ifTrue:
- 		[buffer1
- 			at: 1
- 			put: ((buffer1 at: 1) isCharacter
- 					ifTrue: [(aString at: size) asCharacter]
- 					ifFalse: [(aString at: size) asInteger]).
- 		 self primWrite: fileID from: aString startingAt: 1 count: aString basicSize].
- 	^ aString
- !

Item was changed:
  ----- Method: StandardFileStream>>peekLast (in category 'read, write, position') -----
  peekLast
+ 	"Answer the item just put at the end of the stream, if any."
- 	"Return that item just put at the end of the stream"
  
+ 	^lastWritten!
- 	^ buffer1 size > 0 
- 		ifTrue: [buffer1 last]
- 		ifFalse: [nil]
- !



More information about the Packages mailing list