FsFile class

The Deno abstraction for reading and writing files.

This is the most straight forward way of handling files within Deno and is recommended over using the discreet functions within the Deno namespace.

const file = await Deno.open("/foo/bar.txt", { read: true });
const fileInfo = await file.stat();
if (fileInfo.isFile) {
 const buf = new Uint8Array(100);
 const numberOfBytesRead = await file.read(buf); // 11 bytes
 const text = new TextDecoder().decode(buf);  // "hello world"
}
file.close();
Implemented types
Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

FsFile(num rid)
factory

Properties

close ↔ void Function()

Available on Closer, provided by the Closer$Typings extension

getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
read Future<num?> Function(Uint8List)

Available on Reader, provided by the Reader$Typings extension

getter/setter pair
readable ReadableStream<Uint8List>

Available on FsFile, provided by the FsFile$Typings extension

A {@linkcode ReadableStream} instance representing to the byte contents of the file. This makes it easy to interoperate with other web streams based APIs.
no setter
readSync num? Function(Uint8List)

Available on ReaderSync, provided by the ReaderSync$Typings extension

getter/setter pair
rid num

Available on FsFile, provided by the FsFile$Typings extension

The resource ID associated with the file instance. The resource ID should be considered an opaque reference to resource.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
seek Future<num> Function(Object, SeekMode)

Available on Seeker, provided by the Seeker$Typings extension

getter/setter pair
seekSync num Function(Object, SeekMode)

Available on SeekerSync, provided by the SeekerSync$Typings extension

getter/setter pair
writable WritableStream<Uint8List>

Available on FsFile, provided by the FsFile$Typings extension

A {@linkcode WritableStream} instance to write the contents of the file. This makes it easy to interoperate with other web streams based APIs.
no setter
write Future<num> Function(Uint8List)

Available on Writer, provided by the Writer$Typings extension

getter/setter pair
writeSync num Function(Uint8List)

Available on WriterSync, provided by the WriterSync$Typings extension

getter/setter pair

Methods

close() → void

Available on FsFile, provided by the FsFile$Typings extension

Close the file. Closing a file when you are finished with it is important to avoid leaking resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(Uint8List p) Future<num?>

Available on FsFile, provided by the FsFile$Typings extension

Read the file into an array buffer (p).
readSync(Uint8List p) num?

Available on FsFile, provided by the FsFile$Typings extension

Synchronously read from the file into an array buffer (p).
seek(Object offset, SeekMode whence) Future<num>

Available on FsFile, provided by the FsFile$Typings extension

Seek to the given offset under mode given by whence. The call resolves to the new position within the resource (bytes from the start).
seekSync(Object offset, SeekMode whence) num

Available on FsFile, provided by the FsFile$Typings extension

Synchronously seek to the given offset under mode given by whence. The new position within the resource (bytes from the start) is returned.
stat() Future<FileInfo>

Available on FsFile, provided by the FsFile$Typings extension

Resolves to a {@linkcode Deno.FileInfo} for the file.
statSync() FileInfo

Available on FsFile, provided by the FsFile$Typings extension

Synchronously returns a {@linkcode Deno.FileInfo} for the file.
toString() String
A string representation of this object.
inherited
truncate([num? len]) Future<void>

Available on FsFile, provided by the FsFile$Typings extension

Truncates (or extends) the file to reach the specified len. If len is not specified, then the entire file contents are truncated.
truncateSync([num? len]) → void

Available on FsFile, provided by the FsFile$Typings extension

Synchronously truncates (or extends) the file to reach the specified len. If len is not specified, then the entire file contents are truncated.
write(Uint8List p) Future<num>

Available on FsFile, provided by the FsFile$Typings extension

Write the contents of the array buffer (p) to the file.
writeSync(Uint8List p) num

Available on FsFile, provided by the FsFile$Typings extension

Synchronously write the contents of the array buffer (p) to the file.

Operators

operator ==(Object other) bool
The equality operator.
inherited