Squeak Class Documentation category index | class index  
 
AsyncFile
  category: System-Files
  superclass: Object
  subclasses:

An asynchronous file allows simple file read and write operations to be performed in parallel with other processing. This is useful in multimedia applications that need to stream large amounts of sound or image data from or to a file while doing other work.

instance methods
  as yet unclassified
  close
fileHandle
open:forWrite:
readByteCount:fromFilePosition:onCompletionDo:
test:fileName:
waitForCompletion
writeBuffer:atFilePosition:onCompletionDo:

  primitives
  primClose:
primOpen:forWrite:semaIndex:
primReadResult:intoBuffer:at:count:
primReadStart:fPosition:count:
primWriteResult:
primWriteStart:fPosition:fromBuffer:at:count:

class methods
  class initialization
  initialize

instance methods
  as yet unclassified top  
 

close


 

fileHandle


 

open:forWrite:

Open a file of the given name, and return a handle for that file. Answer the receiver if the primitive succeeds, nil otherwise.
If openForWrite is true, then:
if there is no existing file with this name, then create one
else open the existing file in read-write mode
otherwise:
if there is an existing file with this name, then open it read-only
else answer nil.


 

readByteCount:fromFilePosition:onCompletionDo:

Start a read operation to read byteCount's from the given position in this file. and fork a process to await its completion. When the operation completes, evaluate the given block. Note that, since the completion block may run asynchronous, the client may need to use a SharedQueue or a semaphore for synchronization.


 

test:fileName:

AsyncFile new test: 10000 fileName: 'testData'


 

waitForCompletion


 

writeBuffer:atFilePosition:onCompletionDo:

Start an operation to write the contents of the buffer at given position in this file, and fork a process to await its completion. When the write completes, evaluate the given block. Note that, since the completion block runs asynchronously, the client may need to use a SharedQueue or a semaphore for synchronization.


  primitives top  
 

primClose:

Close this file. Do nothing if primitive fails.


 

primOpen:forWrite:semaIndex:

Open a file of the given name, and return a handle for that file. Answer the receiver if the primitive succeeds, nil otherwise.


 

primReadResult:intoBuffer:at:count:

Copy the result of the last read operation into the given buffer starting at the given index. The buffer may be any sort of bytes or words object, excluding CompiledMethods. Answer the number of bytes read. A negative result means:
-1 the last operation is still in progress
-2 the last operation encountered an error


 

primReadStart:fPosition:count:

Start a read operation of count bytes starting at the given offset in the given file.


 

primWriteResult:

Answer the number of bytes written. A negative result means:
-1 the last operation is still in progress
-2 the last operation encountered an error


 

primWriteStart:fPosition:fromBuffer:at:count:

Start a write operation of count bytes starting at the given index in the given buffer. The buffer may be any sort of bytes or words object, excluding CompiledMethods. The contents of the buffer are copied into an internal buffer immediately, so the buffer can be reused after the write operation has been started. Fail if there is insufficient C heap to allocate an internal buffer of the requested size.


class methods
  class initialization top  
 

initialize

AsyncFile initialize