new AsyncFile()
Represents a file on the file-system which can be read from, or written to asynchronously.
- Source:
Methods
-
close(handler)
-
Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.
Parameters:
Name Type Description handlerfunction the handler - Source:
-
drainHandler(handler) → {AsyncFile}
-
Parameters:
Name Type Description handlerfunction - Source:
Returns:
- Type
- AsyncFile
-
endHandler(endHandler) → {AsyncFile}
-
Parameters:
Name Type Description endHandlerfunction - Source:
Returns:
- Type
- AsyncFile
-
exceptionHandler(handler) → {AsyncFile}
-
Parameters:
Name Type Description handlerfunction - Source:
Returns:
- Type
- AsyncFile
-
flush(handler) → {AsyncFile}
-
Same as AsyncFile#flush but the handler will be called when the flush is complete or if an error occurs
Parameters:
Name Type Description handlerfunction - Source:
Returns:
- Type
- AsyncFile
-
handler(handler) → {AsyncFile}
-
Parameters:
Name Type Description handlerfunction - Source:
Returns:
- Type
- AsyncFile
-
pause() → {AsyncFile}
-
- Source:
Returns:
- Type
- AsyncFile
-
read(buffer, offset, position, length, handler) → {AsyncFile}
-
Reads
lengthbytes of data from the file at positionpositionin the file, asynchronously.The read data will be written into the specified
Buffer bufferat positionoffset.If data is read past the end of the file then zero bytes will be read.
When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
The handler will be called when the close is complete, or if an error occurs.
Parameters:
Name Type Description bufferBuffer the buffer to read into offsetnumber the offset into the buffer where the data will be read positionnumber the position in the file where to start reading lengthnumber the number of bytes to read handlerfunction the handler to call when the write is complete - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- AsyncFile
-
resume() → {AsyncFile}
-
- Source:
Returns:
- Type
- AsyncFile
-
setReadBufferSize(readBufferSize) → {AsyncFile}
-
Sets the buffer size that will be used to read the data from the file. Changing this value will impact how much the data will be read at a time from the file system.
Parameters:
Name Type Description readBufferSizenumber the buffer size - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- AsyncFile
-
setReadPos(readPos) → {AsyncFile}
-
Sets the position from which data will be read from when using the file as a ReadStream.
Parameters:
Name Type Description readPosnumber the position in the file - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- AsyncFile
-
setWritePos(writePos) → {AsyncFile}
-
Sets the position from which data will be written when using the file as a WriteStream.
Parameters:
Name Type Description writePosnumber the position in the file - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- AsyncFile
-
setWriteQueueMaxSize(maxSize) → {AsyncFile}
-
Parameters:
Name Type Description maxSizenumber - Source:
Returns:
- Type
- AsyncFile
-
write(buffer, position, handler) → {AsyncFile}
-
Write a Buffer to the file at position
positionin the file, asynchronously.If
positionlies outside of the current size of the file, the file will be enlarged to encompass it.When multiple writes are invoked on the same file there are no guarantees as to order in which those writes actually occur
The handler will be called when the write is complete, or if an error occurs.
Parameters:
Name Type Description bufferBuffer the buffer to write positionnumber the position in the file to write it at handlerfunction the handler to call when the write is complete - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- AsyncFile
-
writeQueueFull() → {boolean}
-
This will return
trueif there are more bytes in the write queue than the value set using AsyncFile#setWriteQueueMaxSize- Source:
Returns:
true if write queue is full- Type
- boolean