Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

FileSystem

40 exports Since v1.0.0 Source

Constructor

Signature

declare const FileDescriptor: Constructor<Descriptor>
Since v1.0.0

Signature

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

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

Signature

declare class WatchBackend extends any {
constructor();
}

Guard

Since v1.0.0

Signature

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

Layers

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

Signature

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

Model

File

interface
Since v1.0.0

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
Since v1.0.0

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>;
}
Since v1.0.0

Signature

type OpenFlag = "r" | "r+" | "w" | "wx" | "w+" | "wx+" | "a" | "ax" | "a+" | "ax+"
Since v1.0.0

Signature

type SeekMode = "start" | "current"
Since v1.0.0

Signature

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

Options

Since v1.0.0

Signature

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

CopyOptions

interface
Since v1.0.0

Signature

interface CopyOptions {
readonly overwrite?: boolean;
readonly preserveTimestamps?: boolean;
}
Since v1.0.0

Signature

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

Signature

interface MakeTempDirectoryOptions {
readonly directory?: string;
readonly prefix?: string;
}
Since v1.0.0

Signature

interface MakeTempFileOptions {
readonly directory?: string;
readonly prefix?: string;
readonly suffix?: string;
}
Since v1.0.0

Signature

interface OpenFileOptions {
readonly flag?: OpenFlag;
readonly mode?: number;
}
Since v1.0.0

Signature

interface ReadDirectoryOptions {
readonly recursive?: boolean;
}

RemoveOptions

interface
Since v1.0.0

Signature

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

SinkOptions

interface
Since v1.0.0

Signature

interface SinkOptions extends OpenFileOptions {}

StreamOptions

interface
Since v1.0.0

Signature

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

WatchOptions

interface
Since v1.0.0

Signature

interface WatchOptions {
readonly recursive?: boolean;
}
Since v1.0.0

Signature

interface WriteFileOptions {
readonly flag?: OpenFlag;
readonly mode?: number;
}
Since v1.0.0

Signature

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

Other

Since v1.0.0

Sizes

Since v1.0.0

Signature

declare const GiB: (n: number) => Size
Since v1.0.0

Signature

declare const KiB: (n: number) => Size
Since v1.0.0

Signature

declare const MiB: (n: number) => Size
Since v1.0.0

Signature

declare const PiB: (n: number) => Size
Since v1.0.0

Signature

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

Size

type
Since v1.0.0

Represents a size in bytes.

Signature

type Size = Brand.Branded<bigint, "Size">
Since v1.0.0

Represents a size in bytes.

Signature

type SizeInput = bigint | number | Size
Since v1.0.0

Signature

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

Tag

Signature

declare const FileSystem: Tag<FileSystem, FileSystem>

Type Id

Signature

declare const FileTypeId: unique symbol
Since v1.0.0

Signature

type FileTypeId = typeof FileTypeId