Performing low-level file operations on streams
Because the file streams in VA Smalltalk are implemented using the CfsFileDescriptor class, it is possible to obtain the CfsFileDescriptor instance that a file stream is streaming over. To do this, send the fileDescriptor message to the file stream instance. The CfsFileDescriptor instance that is answered can then be used for low-level file descriptor operations. An example of cooperation between streams and file descriptors is shown below:
"An example of combining file descriptor locking with file streams"
| fileStream |
(fileStream := CfsReadWriteFileStream openEmpty: 'lockable.fil') isCfsError
ifTrue: [^self error: fileStream message].
fileStream nextPutAll: 'This is a LOCKED area'.
"Lock the word LOCKED"
fileStream fileDescriptor lock: FMDLOCK start: 10 len: 6.
"Unlock it"
fileStream fileDescriptor unlock: FMDLOCK start: 10 len: 6.
"Close the file stream"
fileStream close.
Last modified date: 01/29/2015