FileInterface representing an open file handle.
Details
Provides low-level file operations including reading, writing, seeking, and retrieving file information. File handles are automatically managed within scoped operations to ensure proper cleanup.
Example (Working with file handles)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Open a file and work with the handle
yield* Effect.scoped(
Effect.gen(function*() {
const file = yield* fs.open("./data.txt", { flag: "r+" })
// Get file information
const stats = yield* file.stat
yield* Console.log(`File size: ${stats.size} bytes`)
// Read from specific position
yield* file.seek(10, "start")
const buffer = new Uint8Array(5)
const bytesRead = yield* file.read(buffer)
yield* Console.log(`Read ${bytesRead} bytes:`, buffer)
// Write data
const data = new TextEncoder().encode("Hello")
yield* file.write(data)
yield* file.sync // Flush to disk
})
)
})export interface File {
readonly [const FileTypeId: "~effect/platform/FileSystem/File"Runtime type identifier attached to FileSystem.File handles and used by
isFile to recognize them.
Details
This marker is part of the runtime representation of file handles. Prefer
isFile when narrowing unknown values.
FileTypeId]: typeof const FileTypeId: "~effect/platform/FileSystem/File"Runtime type identifier attached to FileSystem.File handles and used by
isFile to recognize them.
Details
This marker is part of the runtime representation of file handles. Prefer
isFile when narrowing unknown values.
FileTypeId
readonly File.fd: Brand.Branded<number, "FileDescriptor">fd: File.type File.Descriptor = Brand.Branded<number, "FileDescriptor">Branded type for file descriptors.
Details
File descriptors are numeric handles used by the operating system
to identify open files. The branded type ensures type safety.
Descriptor
readonly File.stat: Effect.Effect<File.Info, PlatformError>(property) File.stat: {
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;
}
stat: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<File.interface File.InfoComprehensive file information structure.
Details
Contains metadata about a file or directory including type, timestamps,
permissions, and size information. This structure is returned by file
stat operations.
Example (Inspecting file information)
import { Effect, FileSystem, Option } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
const path = yield* fs.makeTempFile({ prefix: "info-" })
yield* fs.writeFileString(path, "hello")
const info: FileSystem.File.Info = yield* fs.stat(path)
console.log(`File type: ${info.type}`) // "File type: File"
console.log(`File size: ${info.size} bytes`) // "File size: 5 bytes"
console.log(`Mode: ${info.mode.toString(8)}`) // Octal permissions
// Handle optional timestamps without inventing a fallback date
const modified = Option.match(info.mtime, {
onNone: () => "unavailable",
onSome: (mtime) => mtime.toISOString()
})
console.log(`Modified: ${modified}`)
// Check if it's a regular file
if (info.type === "File") {
console.log("Processing regular file...") // "Processing regular file..."
}
yield* fs.remove(path)
})
Info, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>seek: (offset: SizeInputoffset: type SizeInput = anyInput type for size parameters that accepts multiple numeric types.
Details
This union type allows file system operations to accept size values in
different formats for convenience, which are then normalized to the
branded Size type internally.
Example (Using size inputs)
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// All of these are valid SizeInput values
yield* fs.truncate("file1.txt", 1024) // number
yield* fs.truncate("file2.txt", BigInt(2048)) // bigint
yield* fs.truncate("file3.txt", FileSystem.Size(4096)) // Size
})
SizeInput, from: SeekModefrom: type SeekMode = "start" | "current"Specifies the reference point for seeking within an open file.
When to use
Use with File handles when positioning the cursor before a read or write
and the offset must be interpreted from either the start of the file or the
current cursor.
Details
"start" seeks from the beginning of the file.
"current" seeks from the current cursor position.
SeekMode) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
readonly File.sync: Effect.Effect<void, PlatformError>(property) File.sync: {
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;
}
sync: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>read: (buffer: Uint8Array<ArrayBufferLike>buffer: interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<type Size = Brand.Branded<bigint, "Size">Represents a file size in bytes using a branded bigint.
Details
This type ensures type safety when working with file sizes, preventing
accidental mixing of regular numbers with size values. The underlying
bigint allows for handling very large file sizes beyond JavaScript's
number precision limits.
Example (Creating branded file sizes)
import { Effect, FileSystem } from "effect"
// Create sizes using the Size constructor
const smallFile = FileSystem.Size(1024) // 1 KB
const largeFile = FileSystem.Size(BigInt("9007199254740992")) // Very large
// Use with file operations
const truncateToSize = Effect.fnUntraced(function*(path: string, size: FileSystem.Size) {
const fs = yield* FileSystem.FileSystem
return yield* fs.truncate(path, size)
})
Creates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>readAlloc: (size: SizeInputsize: type SizeInput = anyInput type for size parameters that accepts multiple numeric types.
Details
This union type allows file system operations to accept size values in
different formats for convenience, which are then normalized to the
branded Size type internally.
Example (Using size inputs)
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// All of these are valid SizeInput values
yield* fs.truncate("file1.txt", 1024) // number
yield* fs.truncate("file2.txt", BigInt(2048)) // bigint
yield* fs.truncate("file3.txt", FileSystem.Size(4096)) // Size
})
SizeInput) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array>, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>truncate: (length: SizeInputlength?: type SizeInput = anyInput type for size parameters that accepts multiple numeric types.
Details
This union type allows file system operations to accept size values in
different formats for convenience, which are then normalized to the
branded Size type internally.
Example (Using size inputs)
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// All of these are valid SizeInput values
yield* fs.truncate("file1.txt", 1024) // number
yield* fs.truncate("file2.txt", BigInt(2048)) // bigint
yield* fs.truncate("file3.txt", FileSystem.Size(4096)) // Size
})
SizeInput) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>write: (buffer: Uint8Array<ArrayBufferLike>buffer: interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<type Size = Brand.Branded<bigint, "Size">Represents a file size in bytes using a branded bigint.
Details
This type ensures type safety when working with file sizes, preventing
accidental mixing of regular numbers with size values. The underlying
bigint allows for handling very large file sizes beyond JavaScript's
number precision limits.
Example (Creating branded file sizes)
import { Effect, FileSystem } from "effect"
// Create sizes using the Size constructor
const smallFile = FileSystem.Size(1024) // 1 KB
const largeFile = FileSystem.Size(BigInt("9007199254740992")) // Very large
// Use with file operations
const truncateToSize = Effect.fnUntraced(function*(path: string, size: FileSystem.Size) {
const fs = yield* FileSystem.FileSystem
return yield* fs.truncate(path, size)
})
Creates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
readonly File.writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>writeAll: (buffer: Uint8Array<ArrayBufferLike>buffer: interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
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;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError>
}
/**
* Namespace containing types associated with open file handles, including file
* descriptors, entry kinds, and stat information.
*
* @since 4.0.0
*/
export declare namespace File {
/**
* Branded type for file descriptors.
*
* **Details**
*
* File descriptors are numeric handles used by the operating system
* to identify open files. The branded type ensures type safety.
*
* @category file
* @since 4.0.0
*/
export type type File.Descriptor = Brand.Branded<number, "FileDescriptor">Branded type for file descriptors.
Details
File descriptors are numeric handles used by the operating system
to identify open files. The branded type ensures type safety.
Descriptor = import BrandBrand.type Brand.Branded = /*unresolved*/ anyBranded<number, "FileDescriptor">
/**
* Enumeration of possible file system entry types.
*
* **Details**
*
* Represents the different types of entries that can exist in a file system,
* from regular files to special device files and symbolic links.
*
* @category file
* @since 4.0.0
*/
export type type File.Type = "Unknown" | "File" | "Directory" | "SymbolicLink" | "BlockDevice" | "CharacterDevice" | "FIFO" | "Socket"Enumeration of possible file system entry types.
Details
Represents the different types of entries that can exist in a file system,
from regular files to special device files and symbolic links.
Type =
| "File"
| "Directory"
| "SymbolicLink"
| "BlockDevice"
| "CharacterDevice"
| "FIFO"
| "Socket"
| "Unknown"
/**
* Comprehensive file information structure.
*
* **Details**
*
* Contains metadata about a file or directory including type, timestamps,
* permissions, and size information. This structure is returned by file
* stat operations.
*
* **Example** (Inspecting file information)
*
* ```ts
* import { Effect, FileSystem, Option } from "effect"
*
* const program = Effect.gen(function*() {
* const fs = yield* FileSystem.FileSystem
*
* const path = yield* fs.makeTempFile({ prefix: "info-" })
* yield* fs.writeFileString(path, "hello")
*
* const info: FileSystem.File.Info = yield* fs.stat(path)
*
* console.log(`File type: ${info.type}`) // "File type: File"
* console.log(`File size: ${info.size} bytes`) // "File size: 5 bytes"
* console.log(`Mode: ${info.mode.toString(8)}`) // Octal permissions
*
* // Handle optional timestamps without inventing a fallback date
* const modified = Option.match(info.mtime, {
* onNone: () => "unavailable",
* onSome: (mtime) => mtime.toISOString()
* })
* console.log(`Modified: ${modified}`)
*
* // Check if it's a regular file
* if (info.type === "File") {
* console.log("Processing regular file...") // "Processing regular file..."
* }
*
* yield* fs.remove(path)
* })
* ```
*
* @category file
* @since 4.0.0
*/
export interface interface File.InfoComprehensive file information structure.
Details
Contains metadata about a file or directory including type, timestamps,
permissions, and size information. This structure is returned by file
stat operations.
Example (Inspecting file information)
import { Effect, FileSystem, Option } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
const path = yield* fs.makeTempFile({ prefix: "info-" })
yield* fs.writeFileString(path, "hello")
const info: FileSystem.File.Info = yield* fs.stat(path)
console.log(`File type: ${info.type}`) // "File type: File"
console.log(`File size: ${info.size} bytes`) // "File size: 5 bytes"
console.log(`Mode: ${info.mode.toString(8)}`) // Octal permissions
// Handle optional timestamps without inventing a fallback date
const modified = Option.match(info.mtime, {
onNone: () => "unavailable",
onSome: (mtime) => mtime.toISOString()
})
console.log(`Modified: ${modified}`)
// Check if it's a regular file
if (info.type === "File") {
console.log("Processing regular file...") // "Processing regular file..."
}
yield* fs.remove(path)
})
Info {
readonly File.Info.type: Typetype: type File.Type = "Unknown" | "File" | "Directory" | "SymbolicLink" | "BlockDevice" | "CharacterDevice" | "FIFO" | "Socket"Enumeration of possible file system entry types.
Details
Represents the different types of entries that can exist in a file system,
from regular files to special device files and symbolic links.
Type
readonly File.Info.mtime: Option.Option<Date>mtime: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<Date>
readonly File.Info.atime: Option.Option<Date>atime: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<Date>
readonly File.Info.birthtime: Option.Option<Date>birthtime: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<Date>
readonly File.Info.dev: numberdev: number
readonly File.Info.ino: Option.Option<number>ino: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
readonly File.Info.mode: numbermode: number
readonly File.Info.nlink: Option.Option<number>nlink: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
readonly File.Info.uid: Option.Option<number>uid: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
readonly File.Info.gid: Option.Option<number>gid: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
readonly File.Info.rdev: Option.Option<number>rdev: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
readonly File.Info.size: Sizesize: type Size = Brand.Branded<bigint, "Size">Represents a file size in bytes using a branded bigint.
Details
This type ensures type safety when working with file sizes, preventing
accidental mixing of regular numbers with size values. The underlying
bigint allows for handling very large file sizes beyond JavaScript's
number precision limits.
Example (Creating branded file sizes)
import { Effect, FileSystem } from "effect"
// Create sizes using the Size constructor
const smallFile = FileSystem.Size(1024) // 1 KB
const largeFile = FileSystem.Size(BigInt("9007199254740992")) // Very large
// Use with file operations
const truncateToSize = Effect.fnUntraced(function*(path: string, size: FileSystem.Size) {
const fs = yield* FileSystem.FileSystem
return yield* fs.truncate(path, size)
})
Creates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size
readonly File.Info.blksize: Option.Option<Size>blksize: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<type Size = Brand.Branded<bigint, "Size">Represents a file size in bytes using a branded bigint.
Details
This type ensures type safety when working with file sizes, preventing
accidental mixing of regular numbers with size values. The underlying
bigint allows for handling very large file sizes beyond JavaScript's
number precision limits.
Example (Creating branded file sizes)
import { Effect, FileSystem } from "effect"
// Create sizes using the Size constructor
const smallFile = FileSystem.Size(1024) // 1 KB
const largeFile = FileSystem.Size(BigInt("9007199254740992")) // Very large
// Use with file operations
const truncateToSize = Effect.fnUntraced(function*(path: string, size: FileSystem.Size) {
const fs = yield* FileSystem.FileSystem
return yield* fs.truncate(path, size)
})
Creates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size>
readonly File.Info.blocks: Option.Option<number>blocks: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<number>
}
}