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

This class also provides a readStream and a writeStream. This allows the data to be pumped to and from other streams, e.g. an HttpClientRequest instance using the Pump class.

Instances of AsyncFile are not thread-safe

no subtypes hierarchy

Initializer
AsyncFile(String path, AsyncFile delegate)
Attributes
readStreamshared ReadStream readStream
stringshared actual String string

A developer-friendly string representing the instance. Concatenates the name of the concrete class of the instance with the hash of the instance. Subclasses are encouraged to refine this implementation to produce a more meaningful representation.

Refines Object.string (string)
writeStreamshared WriteStream writeStream
Inherited Attributes
Attributes inherited from: Object
hash
Methods
closeshared Promise<Anything> close()

Close the file. The actual close happens asynchronously. The returned promise will be resolved when the close is complete, or an error occurs.

flushshared Promise<Anything> flush()

Flush any writes made to this file to underlying persistent storage.

If the file was opened with flush set to true then calling this method will have no effect.

The actual flush will happen asynchronously.

The returned promise will be resolved when the flush is complete or if an error occurs

readshared Promise<Buffer> read(Buffer buffer, Integer offset, Integer position, Integer length)

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 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 returned promise will be resolved when the close is complete, or if an error occurs.

writeshared Promise<Anything> write(Buffer buffer, Integer position)

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 returned promise will be resolved when the write is complete, or if an error occurs.

Inherited Methods
Methods inherited from: Object
equals