SizeRepresents 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)
})export type 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 = import BrandBrand.type Brand.Branded = /*unresolved*/ anyBranded<bigint, "Size">
/**
* Input 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)
*
* ```ts
* 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
* })
* ```
*
* @category sizes
* @since 4.0.0
*/
export type 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 = bigint | number | 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
/**
* 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)
*
* ```ts
* 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)
* })
* })
* ```
*
* @category sizes
* @since 4.0.0
*/
export const const Size: (bytes: SizeInput) => SizeRepresents 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 = (bytes: SizeInputbytes: 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): 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 => typeof bytes: SizeInputbytes === "bigint" ? bytes: SizeInputbytes as 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 : var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(bytes: SizeInputbytes) as 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