(fileSystem: Partial<FileSystem>): FileSystemCreates a stub FileSystem implementation for tests.
Details
By default, exists returns false, remove succeeds, many file operations
fail with PlatformError NotFound, and temporary-directory/file operations
die as not implemented. Pass method overrides to provide the behavior needed
by a specific test without touching the real file system.
Example (Creating a no-op FileSystem)
import { Effect, FileSystem, PlatformError } from "effect"
// Create a test filesystem that only allows reading specific files
const testFs = FileSystem.makeNoop({
readFileString: (path) => {
if (path === "test-config.json") {
return Effect.succeed("{\"test\": true}")
}
return Effect.fail(
PlatformError.systemError({
_tag: "NotFound",
module: "FileSystem",
method: "readFileString",
description: "File not found",
pathOrDescriptor: path
})
)
},
exists: (path) => Effect.succeed(path === "test-config.json")
})
// Use in tests
const program = Effect.gen(function*() {
const content = yield* testFs.readFileString("test-config.json")
// Will succeed with mocked content
})
// Test with the no-op filesystem
const testProgram = Effect.provideService(
program,
FileSystem.FileSystem,
testFs
)export const const makeNoop: (
fileSystem: Partial<FileSystem>
) => FileSystem
Creates a stub FileSystem implementation for tests.
Details
By default, exists returns false, remove succeeds, many file operations
fail with PlatformError NotFound, and temporary-directory/file operations
die as not implemented. Pass method overrides to provide the behavior needed
by a specific test without touching the real file system.
Example (Creating a no-op FileSystem)
import { Effect, FileSystem, PlatformError } from "effect"
// Create a test filesystem that only allows reading specific files
const testFs = FileSystem.makeNoop({
readFileString: (path) => {
if (path === "test-config.json") {
return Effect.succeed("{\"test\": true}")
}
return Effect.fail(
PlatformError.systemError({
_tag: "NotFound",
module: "FileSystem",
method: "readFileString",
description: "File not found",
pathOrDescriptor: path
})
)
},
exists: (path) => Effect.succeed(path === "test-config.json")
})
// Use in tests
const program = Effect.gen(function*() {
const content = yield* testFs.readFileString("test-config.json")
// Will succeed with mocked content
})
// Test with the no-op filesystem
const testProgram = Effect.provideService(
program,
FileSystem.FileSystem,
testFs
)
makeNoop = (fileSystem: Partial<FileSystem>fileSystem: type Partial<T> = {
[P in keyof T]?: T[P] | undefined
}
Make all properties in T optional
Partial<FileSystem>): FileSystem =>
const FileSystem: Context.Service<
FileSystem,
FileSystem
>
const FileSystem: {
key: string;
Service: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
};
of: (this: void, self: FileSystem) => FileSystem;
context: (self: FileSystem) => Context.Context<FileSystem>;
use: (f: (service: FileSystem) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, FileSystem | R>;
useSync: (f: (service: FileSystem) => A) => Effect.Effect<A, never, FileSystem>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Core interface for file system operations in Effect.
Details
The FileSystem interface provides a comprehensive set of file and directory operations
that work cross-platform. All operations return Effect values that can be composed,
transformed, and executed safely with proper error handling.
Example (Accessing file system operations)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Basic file operations
const exists = yield* fs.exists("./config.json")
if (!exists) {
yield* fs.writeFileString("./config.json", "{\"env\": \"development\"}")
}
// Directory operations
yield* fs.makeDirectory("./logs", { recursive: true })
// File information
const stats = yield* fs.stat("./config.json")
yield* Console.log(`File size: ${stats.size} bytes`)
// Streaming operations
const content = yield* fs.readFileString("./config.json")
yield* Console.log("Config:", content)
})
Service tag for platform file-system operations.
When to use
Use to access or provide operations for files, directories, permissions,
streams, and sinks through the Effect context.
Details
This key is used to provide and access the FileSystem service in the Effect context.
Example (Accessing and providing FileSystem)
import { Effect, FileSystem } from "effect"
// Access the FileSystem service
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
const exists = yield* fs.exists("./data.txt")
if (exists) {
const content = yield* fs.readFileString("./data.txt")
yield* Effect.log("File content:", content)
}
})
// Provide a custom FileSystem implementation
declare const platformImpl: Omit<
FileSystem.FileSystem,
"exists" | "readFileString" | "stream" | "sink" | "writeFileString"
>
const customFs = FileSystem.make(platformImpl)
const withCustomFs = Effect.provideService(
program,
FileSystem.FileSystem,
customFs
)
FileSystem.Service<FileSystem, FileSystem>.of(this: void, self: FileSystem): FileSystemof({
[const TypeId: "~effect/platform/FileSystem"TypeId]: const TypeId: "~effect/platform/FileSystem"TypeId,
FileSystem.access: (path: string, options?: {
readonly ok?: boolean | undefined;
readonly readable?: boolean | undefined;
readonly writable?: boolean | undefined;
}) => Effect.Effect<void, PlatformError>
Checks whether a file can be accessed.
You can optionally specify the level of access to check for.
access(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("access", path: stringpath))
},
FileSystem.chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>Change the permissions of a file.
chmod(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("chmod", path: stringpath))
},
FileSystem.chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>Change the owner and group of a file.
chown(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("chown", path: stringpath))
},
FileSystem.copy: (fromPath: string, toPath: string, options?: {
readonly overwrite?: boolean | undefined;
readonly preserveTimestamps?: boolean | undefined;
}) => Effect.Effect<void, PlatformError>
Copy a file or directory from fromPath to toPath.
Details
Equivalent to cp -r.
copy(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("copy", path: stringpath))
},
FileSystem.copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>Copy a file from fromPath to toPath.
copyFile(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("copyFile", path: stringpath))
},
FileSystem.glob: (pattern: string, options?: {
readonly root?: string | undefined;
readonly exclude?: ReadonlyArray<string> | undefined;
}) => Effect.Effect<Array<string>, PlatformError>
Glob a directory.
glob(pattern: stringpattern) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("glob", pattern: stringpattern))
},
FileSystem.exists: (path: string) => Effect.Effect<boolean, PlatformError>Checks whether a path exists.
exists() {
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(false)
},
FileSystem.link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>Create a hard link from fromPath to toPath.
link(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("link", path: stringpath))
},
FileSystem.makeDirectory: (path: string, options?: {
readonly recursive?: boolean | undefined;
readonly mode?: number | undefined;
}) => Effect.Effect<void, PlatformError>
Create a directory at path. You can optionally specify the mode and
whether to recursively create nested directories.
makeDirectory() {
return import EffectEffect.const die: (
defect: unknown
) => Effect<never>
Creates an effect that terminates a fiber with a specified error.
When to use
Use when you need an Effect to report an unrecoverable defect instead of a
typed error.
Details
The die function is used to signal a defect, which represents a critical
and unexpected error in the code. When invoked, it produces an effect that
does not handle the error and instead terminates the fiber.
The error channel of the resulting effect is of type never, indicating that
it cannot recover from this failure.
Example (Failing on division by zero)
import { Effect } from "effect"
const divide = (a: number, b: number) =>
b === 0
? Effect.die(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// ┌─── Effect<number, never, never>
// ▼
const program = divide(1, 0)
Effect.runPromise(program).catch(console.error)
// Output:
// (FiberFailure) Error: Cannot divide by zero
// ...stack trace...
die("not implemented")
},
FileSystem.makeTempDirectory: (options?: {
readonly directory?: string | undefined;
readonly prefix?: string | undefined;
}) => Effect.Effect<string, PlatformError>
Create a temporary directory.
Details
By default the directory will be created inside the system's default
temporary directory, but you can specify a different location by setting
the directory option.
You can also specify a prefix for the directory name by setting the
prefix option.
makeTempDirectory() {
return import EffectEffect.const die: (
defect: unknown
) => Effect<never>
Creates an effect that terminates a fiber with a specified error.
When to use
Use when you need an Effect to report an unrecoverable defect instead of a
typed error.
Details
The die function is used to signal a defect, which represents a critical
and unexpected error in the code. When invoked, it produces an effect that
does not handle the error and instead terminates the fiber.
The error channel of the resulting effect is of type never, indicating that
it cannot recover from this failure.
Example (Failing on division by zero)
import { Effect } from "effect"
const divide = (a: number, b: number) =>
b === 0
? Effect.die(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// ┌─── Effect<number, never, never>
// ▼
const program = divide(1, 0)
Effect.runPromise(program).catch(console.error)
// Output:
// (FiberFailure) Error: Cannot divide by zero
// ...stack trace...
die("not implemented")
},
FileSystem.makeTempDirectoryScoped: (options?: {
readonly directory?: string | undefined;
readonly prefix?: string | undefined;
}) => Effect.Effect<string, PlatformError, Scope>
Create a temporary directory inside a scope.
Details
Functionally equivalent to makeTempDirectory, but the directory will be
automatically deleted when the scope is closed.
makeTempDirectoryScoped() {
return import EffectEffect.const die: (
defect: unknown
) => Effect<never>
Creates an effect that terminates a fiber with a specified error.
When to use
Use when you need an Effect to report an unrecoverable defect instead of a
typed error.
Details
The die function is used to signal a defect, which represents a critical
and unexpected error in the code. When invoked, it produces an effect that
does not handle the error and instead terminates the fiber.
The error channel of the resulting effect is of type never, indicating that
it cannot recover from this failure.
Example (Failing on division by zero)
import { Effect } from "effect"
const divide = (a: number, b: number) =>
b === 0
? Effect.die(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// ┌─── Effect<number, never, never>
// ▼
const program = divide(1, 0)
Effect.runPromise(program).catch(console.error)
// Output:
// (FiberFailure) Error: Cannot divide by zero
// ...stack trace...
die("not implemented")
},
FileSystem.makeTempFile: (options?: {
readonly directory?: string | undefined;
readonly prefix?: string | undefined;
readonly suffix?: string | undefined;
}) => Effect.Effect<string, PlatformError>
Create a temporary file.
The directory creation is functionally equivalent to makeTempDirectory.
The file name will be a randomly generated string.
makeTempFile() {
return import EffectEffect.const die: (
defect: unknown
) => Effect<never>
Creates an effect that terminates a fiber with a specified error.
When to use
Use when you need an Effect to report an unrecoverable defect instead of a
typed error.
Details
The die function is used to signal a defect, which represents a critical
and unexpected error in the code. When invoked, it produces an effect that
does not handle the error and instead terminates the fiber.
The error channel of the resulting effect is of type never, indicating that
it cannot recover from this failure.
Example (Failing on division by zero)
import { Effect } from "effect"
const divide = (a: number, b: number) =>
b === 0
? Effect.die(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// ┌─── Effect<number, never, never>
// ▼
const program = divide(1, 0)
Effect.runPromise(program).catch(console.error)
// Output:
// (FiberFailure) Error: Cannot divide by zero
// ...stack trace...
die("not implemented")
},
FileSystem.makeTempFileScoped: (options?: {
readonly directory?: string | undefined;
readonly prefix?: string | undefined;
readonly suffix?: string | undefined;
}) => Effect.Effect<string, PlatformError, Scope>
Create a temporary file inside a scope.
Details
Functionally equivalent to makeTempFile, but the file will be
automatically deleted when the scope is closed.
makeTempFileScoped() {
return import EffectEffect.const die: (
defect: unknown
) => Effect<never>
Creates an effect that terminates a fiber with a specified error.
When to use
Use when you need an Effect to report an unrecoverable defect instead of a
typed error.
Details
The die function is used to signal a defect, which represents a critical
and unexpected error in the code. When invoked, it produces an effect that
does not handle the error and instead terminates the fiber.
The error channel of the resulting effect is of type never, indicating that
it cannot recover from this failure.
Example (Failing on division by zero)
import { Effect } from "effect"
const divide = (a: number, b: number) =>
b === 0
? Effect.die(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// ┌─── Effect<number, never, never>
// ▼
const program = divide(1, 0)
Effect.runPromise(program).catch(console.error)
// Output:
// (FiberFailure) Error: Cannot divide by zero
// ...stack trace...
die("not implemented")
},
FileSystem.open: (path: string, options?: {
readonly flag?: OpenFlag | undefined;
readonly mode?: number | undefined;
}) => Effect.Effect<File, PlatformError, Scope>
Open a file at path with the specified options.
Details
The file handle will be automatically closed when the scope is closed.
open(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("open", path: stringpath))
},
FileSystem.readDirectory: (path: string, options?: {
readonly recursive?: boolean | undefined;
}) => Effect.Effect<Array<string>, PlatformError>
List the contents of a directory.
Details
You can recursively list the contents of nested directories by setting the
recursive option.
readDirectory(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("readDirectory", path: stringpath))
},
FileSystem.readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>Read the contents of a file.
readFile(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("readFile", path: stringpath))
},
FileSystem.readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>Read the contents of a file.
readFileString(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("readFileString", path: stringpath))
},
FileSystem.readLink: (path: string) => Effect.Effect<string, PlatformError>Read the destination of a symbolic link.
readLink(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("readLink", path: stringpath))
},
FileSystem.realPath: (path: string) => Effect.Effect<string, PlatformError>Resolve a path to its canonicalized absolute pathname.
realPath(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("realPath", path: stringpath))
},
FileSystem.remove: (path: string, options?: {
readonly recursive?: boolean | undefined;
readonly force?: boolean | undefined;
}) => Effect.Effect<void, PlatformError>
Remove a file or directory.
remove() {
return import EffectEffect.const void: Effect.Effect<void, never, never>(alias) const void: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Returns an effect that succeeds with void.
void
},
FileSystem.rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>Rename a file or directory.
rename(oldPath: stringoldPath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("rename", oldPath: stringoldPath))
},
FileSystem.sink: (path: string, options?: {
readonly flag?: OpenFlag | undefined;
readonly mode?: number | undefined;
}) => Sink.Sink<void, Uint8Array, never, PlatformError>
Create a writable Sink for the specified path.
sink(path: stringpath) {
return import SinkSink.const fail: <E>(
e: E
) => Sink<never, unknown, never, E>
A sink that always fails with the specified error.
Example (Failing with an error)
import { Effect, Sink, Stream } from "effect"
// Create a sink that always fails
const sink = Sink.fail(new Error("Sink failed"))
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).catch(console.log)
// Output: Error: Sink failed
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("sink", path: stringpath))
},
FileSystem.stat: (path: string) => Effect.Effect<File.Info, PlatformError>Get information about a file at path.
stat(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("stat", path: stringpath))
},
FileSystem.stream: (path: string, options?: {
readonly bytesToRead?: SizeInput | undefined;
readonly chunkSize?: SizeInput | undefined;
readonly offset?: SizeInput | undefined;
}) => Stream.Stream<Uint8Array, PlatformError>
Create a readable Stream for the specified path.
Details
Changing the bufferSize option will change the internal buffer size of
the stream. It defaults to 4.
The chunkSize option will change the size of the chunks emitted by the
stream. It defaults to 64kb.
Changing offset and bytesToRead will change the offset and the number
of bytes to read from the file.
stream(path: stringpath) {
return import StreamStream.const fail: <E>(
error: E
) => Stream<never, E>
Terminates with the specified error.
Example (Failing a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fail("Uh oh!")
const exit = yield* Effect.exit(Stream.runCollect(stream))
yield* Console.log(exit)
// Output: { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
})
Effect.runPromise(program)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("stream", path: stringpath))
},
FileSystem.symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>Create a symbolic link from fromPath to toPath.
symlink(fromPath: stringfromPath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("symlink", fromPath: stringfromPath))
},
FileSystem.truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>Truncate a file to a specified length. If the length is not specified,
the file will be truncated to length 0.
truncate(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("truncate", path: stringpath))
},
FileSystem.utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>Change the file system timestamps of the file at path.
utimes(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("utimes", path: stringpath))
},
FileSystem.watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>Watch a directory or file for changes
watch(path: stringpath) {
return import StreamStream.const fail: <E>(
error: E
) => Stream<never, E>
Terminates with the specified error.
Example (Failing a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fail("Uh oh!")
const exit = yield* Effect.exit(Stream.runCollect(stream))
yield* Console.log(exit)
// Output: { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
})
Effect.runPromise(program)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("watch", path: stringpath))
},
FileSystem.writeFile: (path: string, data: Uint8Array, options?: {
readonly flag?: OpenFlag | undefined;
readonly mode?: number | undefined;
}) => Effect.Effect<void, PlatformError>
Write data to a file at path.
writeFile(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("writeFile", path: stringpath))
},
FileSystem.writeFileString: (path: string, data: string, options?: {
readonly flag?: OpenFlag | undefined;
readonly mode?: number | undefined;
}) => Effect.Effect<void, PlatformError>
Write a string to a file at path.
writeFileString(path: stringpath) {
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const notFound: (
method: string,
path: string
) => PlatformError
notFound("writeFileString", path: stringpath))
},
...fileSystem: Partial<FileSystem>fileSystem
})