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 |
handler |
function
|
the handler |
- Source:
drainHandler(handler) → {AsyncFile}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
AsyncFile
end(data, handler)
Same as but with an handler called when the operation completes
Parameters:
| Name |
Type |
Description |
data |
Buffer
|
|
handler |
function
|
|
- Source:
endHandler(endHandler) → {AsyncFile}
Parameters:
| Name |
Type |
Description |
endHandler |
function
|
|
- Source:
Returns:
-
Type
-
AsyncFile
exceptionHandler(handler) → {AsyncFile}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
AsyncFile
fetch(amount) → {AsyncFile}
Parameters:
| Name |
Type |
Description |
amount |
number
|
|
- 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 |
handler |
function
|
|
- Source:
Returns:
-
Type
-
AsyncFile
getWritePos() → {number}
- Source:
Returns:
the current write position the file is at
-
Type
-
number
handler(handler) → {AsyncFile}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
AsyncFile
pause() → {AsyncFile}
- Source:
Returns:
-
Type
-
AsyncFile
pipe() → {Pipe}
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a
WriteStream.
- Source:
Returns:
a pipe
-
Type
-
Pipe
pipeTo(dst, handler)
Pipe this
ReadStream to the
WriteStream.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler will be
called with the result.
Parameters:
| Name |
Type |
Description |
dst |
WriteStream
|
the destination write stream |
handler |
function
|
|
- Source:
read(buffer, offset, position, length, handler) → {AsyncFile}
Reads
length bytes of data from the file at position
position in the file, asynchronously.
The read data will be written into the specified Buffer buffer at position offset.
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 |
buffer |
Buffer
|
the buffer to read into |
offset |
number
|
the offset into the buffer where the data will be read |
position |
number
|
the position in the file where to start reading |
length |
number
|
the number of bytes to read |
handler |
function
|
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 |
readBufferSize |
number
|
the buffer size |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
AsyncFile
setReadLength(readLength) → {AsyncFile}
Sets the number of bytes that will be read when using the file as a ReadStream.
Parameters:
| Name |
Type |
Description |
readLength |
number
|
the bytes that will be read from the file |
- 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 |
readPos |
number
|
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 |
writePos |
number
|
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 |
maxSize |
number
|
|
- Source:
Returns:
-
Type
-
AsyncFile
write(buffer, position, handler)
Write a Buffer to the file at position
position in the file, asynchronously.
If position lies 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 |
buffer |
Buffer
|
the buffer to write |
position |
number
|
the position in the file to write it at |
handler |
function
|
the handler to call when the write is complete |
- Source:
writeQueueFull() → {boolean}
This will return true if 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