Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AsyncFile

Represents a file on the file-system which can be read from, or written to asynchronously.

This class also implements ReadStream and WriteStream. This allows the data to be piped to and from other streams, e.g. an HttpClientRequest instance, using the Pipe class

Hierarchy

  • AsyncFile

Implements

Index

Methods

close

  • Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

    Returns PromiseLike<void>

  • Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

    Parameters

    Returns void

drainHandler

  • drainHandler(handler: ((res: void) => void) | Handler<void> | null | undefined): AsyncFile
  • Parameters

    • handler: ((res: void) => void) | Handler<void> | null | undefined

    Returns AsyncFile

end

  • Same as {@link WriteStream#end} but with an handler called when the operation completes

    Returns PromiseLike<void>

  • Same as {@link WriteStream#end} but with an handler called when the operation completes

    Parameters

    Returns void

  • Same as but with an handler called when the operation completes

    Parameters

    Returns PromiseLike<void>

  • Same as but with an handler called when the operation completes

    Parameters

    Returns void

endHandler

  • endHandler(endHandler: ((res: void) => void) | Handler<void> | null | undefined): AsyncFile
  • Parameters

    • endHandler: ((res: void) => void) | Handler<void> | null | undefined

    Returns AsyncFile

exceptionHandler

  • Parameters

    Returns AsyncFile

fetch

  • Parameters

    • amount: number

    Returns AsyncFile

flush

  • Same as {@link AsyncFile#flush} but the handler will be called when the flush is complete or if an error occurs

    Returns PromiseLike<void>

  • Same as {@link AsyncFile#flush} but the handler will be called when the flush is complete or if an error occurs

    Parameters

    Returns AsyncFile

getReadLength

  • getReadLength(): number
  • Returns number

getWritePos

  • getWritePos(): number
  • Returns number

handler

  • Parameters

    Returns AsyncFile

lock

  • Like {@link AsyncFile#lock} but the handler will be called when the operation is complete or if an error occurs.

    Returns PromiseLike<AsyncFileLock>

  • Like {@link AsyncFile#lock} but the handler will be called when the operation is complete or if an error occurs.

    Parameters

    Returns void

  • Like {@link AsyncFile#lock} but the handler will be called when the operation is complete or if an error occurs.

    Parameters

    • position: number
    • size: number
    • shared: boolean

    Returns PromiseLike<AsyncFileLock>

  • Like {@link AsyncFile#lock} but the handler will be called when the operation is complete or if an error occurs.

    Parameters

    Returns void

pause

  • Returns AsyncFile

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.

    Returns Pipe<Buffer>

pipeTo

  • 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

    Returns PromiseLike<void>

  • 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

    Returns void

read

  • 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

    • buffer: Buffer
    • offset: number
    • position: number
    • length: number

    Returns PromiseLike<Buffer>

  • 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

    Returns AsyncFile

resume

setReadBufferSize

  • setReadBufferSize(readBufferSize: number): 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

    • readBufferSize: number

    Returns AsyncFile

setReadLength

  • setReadLength(readLength: number): AsyncFile
  • Sets the number of bytes that will be read when using the file as a ReadStream.

    Parameters

    • readLength: number

    Returns AsyncFile

setReadPos

  • Sets the position from which data will be read from when using the file as a ReadStream.

    Parameters

    • readPos: number

    Returns AsyncFile

setWritePos

  • Sets the position from which data will be written when using the file as a WriteStream.

    Parameters

    • writePos: number

    Returns AsyncFile

setWriteQueueMaxSize

  • setWriteQueueMaxSize(maxSize: number): AsyncFile

size

  • Like {@link AsyncFile#size} but the handler will be called when the operation is complete or if an error occurs.

    Returns PromiseLike<number>

  • Like {@link AsyncFile#size} but the handler will be called when the operation is complete or if an error occurs.

    Parameters

    Returns void

sizeBlocking

  • sizeBlocking(): number
  • Like {@link AsyncFile#size} but blocking.

    Returns number

tryLock

  • Try to acquire a non-shared lock on the entire file.

    Returns AsyncFileLock | null

  • Try to acquire a lock on a portion of this file.

    Parameters

    • position: number
    • size: number
    • shared: boolean

    Returns AsyncFileLock | null

write

  • Same as but with an handler called when the operation completes

    Parameters

    Returns PromiseLike<void>

  • Same as but with an handler called when the operation completes

    Parameters

    Returns void

  • 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

    • buffer: Buffer
    • position: number

    Returns PromiseLike<void>

  • 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

    Returns void

writeQueueFull

  • writeQueueFull(): boolean
  • This will return true if there are more bytes in the write queue than the value set using {@link AsyncFile#setWriteQueueMaxSize}

    Returns boolean

Generated using TypeDoc