Skip to content

FileSystem

40 exports Added in v1.0.0 Source

Constructor

Signature

declare const FileDescriptor: Constructor<Descriptor>;

make

Added in v1.0.0 Source

Signature

declare const make: (
  impl: Omit<FileSystem, "exists" | "readFileString" | "stream" | "sink" | "writeFileString">,
) => FileSystem;

makeNoop

Added in v1.0.0 Source

Create a no-op file system that can be used for testing.

Signature

declare const makeNoop: (fileSystem: Partial<FileSystem>) => FileSystem;

Signature

declare const WatchEventCreate: Data.Case.Constructor<WatchEvent.Create, "_tag">;

Signature

declare const WatchEventRemove: Data.Case.Constructor<WatchEvent.Remove, "_tag">;

Signature

declare const WatchEventUpdate: Data.Case.Constructor<WatchEvent.Update, "_tag">;

File Watcher

WatchBackend

Added in v1.0.0 Source

Signature

declare class WatchBackend extends any {
  constructor();
}

Guard

isFile

Added in v1.0.0 Source

Signature

declare function isFile(u: unknown): u is File;

Layers

layerNoop

Added in v1.0.0 Source

Create a no-op file system that can be used for testing.

Signature

declare const layerNoop: (fileSystem: Partial<FileSystem>) => Layer<FileSystem>;

Model

File interface

Added in v1.0.0 Source

Signature

interface File {
  readonly [FileTypeId]: typeof FileTypeId;
  readonly fd: Descriptor;
  readonly read: (buffer: Uint8Array) => Effect<Size, PlatformError>;
  readonly readAlloc: (
    size: SizeInput,
  ) => Effect<Option<Uint8Array<ArrayBufferLike>>, PlatformError>;
  readonly seek: (offset: SizeInput, from: SeekMode) => Effect<void>;
  readonly stat: Effect<Info, PlatformError>;
  readonly sync: Effect<void, PlatformError>;
  readonly truncate: (length?: SizeInput) => Effect<void, PlatformError>;
  readonly write: (buffer: Uint8Array) => Effect<Size, PlatformError>;
  readonly writeAll: (buffer: Uint8Array) => Effect<void, PlatformError>;
}

FileSystem interface

Added in v1.0.0 Source

Signature

interface FileSystem {
  readonly access: (path: string, options?: AccessFileOptions) => Effect<void, PlatformError>;
  readonly chmod: (path: string, mode: number) => Effect<void, PlatformError>;
  readonly chown: (path: string, uid: number, gid: number) => Effect<void, PlatformError>;
  readonly copy: (
    fromPath: string,
    toPath: string,
    options?: CopyOptions,
  ) => Effect<void, PlatformError>;
  readonly copyFile: (fromPath: string, toPath: string) => Effect<void, PlatformError>;
  readonly exists: (path: string) => Effect<boolean, PlatformError>;
  readonly link: (fromPath: string, toPath: string) => Effect<void, PlatformError>;
  readonly makeDirectory: (
    path: string,
    options?: MakeDirectoryOptions,
  ) => Effect<void, PlatformError>;
  readonly makeTempDirectory: (options?: MakeTempDirectoryOptions) => Effect<string, PlatformError>;
  readonly makeTempDirectoryScoped: (
    options?: MakeTempDirectoryOptions,
  ) => Effect<string, PlatformError, Scope>;
  readonly makeTempFile: (options?: MakeTempFileOptions) => Effect<string, PlatformError>;
  readonly makeTempFileScoped: (
    options?: MakeTempFileOptions,
  ) => Effect<string, PlatformError, Scope>;
  readonly open: (path: string, options?: OpenFileOptions) => Effect<File, PlatformError, Scope>;
  readonly readDirectory: (
    path: string,
    options?: ReadDirectoryOptions,
  ) => Effect<Array<string>, PlatformError>;
  readonly readFile: (path: string) => Effect<Uint8Array<ArrayBufferLike>, PlatformError>;
  readonly readFileString: (path: string, encoding?: string) => Effect<string, PlatformError>;
  readonly readLink: (path: string) => Effect<string, PlatformError>;
  readonly realPath: (path: string) => Effect<string, PlatformError>;
  readonly remove: (path: string, options?: RemoveOptions) => Effect<void, PlatformError>;
  readonly rename: (oldPath: string, newPath: string) => Effect<void, PlatformError>;
  readonly sink: (
    path: string,
    options?: SinkOptions,
  ) => Sink<void, Uint8Array<ArrayBufferLike>, never, PlatformError>;
  readonly stat: (path: string) => Effect<Info, PlatformError>;
  readonly stream: (
    path: string,
    options?: StreamOptions,
  ) => Stream<Uint8Array<ArrayBufferLike>, PlatformError>;
  readonly symlink: (fromPath: string, toPath: string) => Effect<void, PlatformError>;
  readonly truncate: (path: string, length?: SizeInput) => Effect<void, PlatformError>;
  readonly utimes: (
    path: string,
    atime: number | Date,
    mtime: number | Date,
  ) => Effect<void, PlatformError>;
  readonly watch: (path: string, options?: WatchOptions) => Stream<WatchEvent, PlatformError>;
  readonly writeFile: (
    path: string,
    data: Uint8Array,
    options?: WriteFileOptions,
  ) => Effect<void, PlatformError>;
  readonly writeFileString: (
    path: string,
    data: string,
    options?: WriteFileStringOptions,
  ) => Effect<void, PlatformError>;
}

OpenFlag type

Added in v1.0.0 Source

Signature

type OpenFlag = "r" | "r+" | "w" | "wx" | "w+" | "wx+" | "a" | "ax" | "a+" | "ax+";

SeekMode type

Added in v1.0.0 Source

Signature

type SeekMode = "start" | "current";

WatchEvent

Added in v1.0.0 Source

WatchEvent type

Added in v1.0.0 Source

Signature

type WatchEvent = WatchEvent.Create | WatchEvent.Update | WatchEvent.Remove;

Options

AccessFileOptions interface

Added in v1.0.0 Source

Signature

interface AccessFileOptions {
  readonly ok?: boolean;
  readonly readable?: boolean;
  readonly writable?: boolean;
}

CopyOptions interface

Added in v1.0.0 Source

Signature

interface CopyOptions {
  readonly overwrite?: boolean;
  readonly preserveTimestamps?: boolean;
}

MakeDirectoryOptions interface

Added in v1.0.0 Source

Signature

interface MakeDirectoryOptions {
  readonly mode?: number;
  readonly recursive?: boolean;
}

MakeTempDirectoryOptions interface

Added in v1.0.0 Source

Signature

interface MakeTempDirectoryOptions {
  readonly directory?: string;
  readonly prefix?: string;
}

MakeTempFileOptions interface

Added in v1.0.0 Source

Signature

interface MakeTempFileOptions {
  readonly directory?: string;
  readonly prefix?: string;
  readonly suffix?: string;
}

OpenFileOptions interface

Added in v1.0.0 Source

Signature

interface OpenFileOptions {
  readonly flag?: OpenFlag;
  readonly mode?: number;
}

ReadDirectoryOptions interface

Added in v1.0.0 Source

Signature

interface ReadDirectoryOptions {
  readonly recursive?: boolean;
}

RemoveOptions interface

Added in v1.0.0 Source

Signature

interface RemoveOptions {
  readonly force?: boolean;
  readonly recursive?: boolean;
}

SinkOptions interface

Added in v1.0.0 Source

Signature

interface SinkOptions extends OpenFileOptions {}

StreamOptions interface

Added in v1.0.0 Source

Signature

interface StreamOptions {
  readonly bufferSize?: number;
  readonly bytesToRead?: SizeInput;
  readonly chunkSize?: SizeInput;
  readonly offset?: SizeInput;
}

WatchOptions interface

Added in v1.0.0 Source

Signature

interface WatchOptions {
  readonly recursive?: boolean;
}

WriteFileOptions interface

Added in v1.0.0 Source

Signature

interface WriteFileOptions {
  readonly flag?: OpenFlag;
  readonly mode?: number;
}

WriteFileStringOptions interface

Added in v1.0.0 Source

Signature

interface WriteFileStringOptions {
  readonly flag?: OpenFlag;
  readonly mode?: number;
}

Other

File

Added in v1.0.0 Source

Sizes

GiB

Added in v1.0.0 Source

Signature

declare const GiB: (n: number) => Size;

KiB

Added in v1.0.0 Source

Signature

declare const KiB: (n: number) => Size;

MiB

Added in v1.0.0 Source

Signature

declare const MiB: (n: number) => Size;

PiB

Added in v1.0.0 Source

Signature

declare const PiB: (n: number) => Size;

Size

Added in v1.0.0 Source

Signature

declare const Size: (bytes: SizeInput) => Size;

Size type

Added in v1.0.0 Source

Represents a size in bytes.

Signature

type Size = Brand.Branded<bigint, "Size">;

SizeInput type

Added in v1.0.0 Source

Represents a size in bytes.

Signature

type SizeInput = bigint | number | Size;

TiB

Added in v1.0.0 Source

Signature

declare const TiB: (n: number) => Size;

Tag

FileSystem

Added in v1.0.0 Source

Signature

declare const FileSystem: Tag<FileSystem, FileSystem>;

Type Id

FileTypeId

Added in v1.0.0 Source

Signature

declare const FileTypeId: unique symbol;

FileTypeId type

Added in v1.0.0 Source

Signature

type FileTypeId = typeof FileTypeId;