(n: number): SizeCreates a Size representing pebibytes (1024⁵ bytes).
Details
Converts a number of pebibytes to the equivalent size in bytes. Uses binary pebibytes (1,125,899,906,842,624 bytes) rather than decimal petabytes. This function uses BigInt arithmetic to handle the very large numbers involved.
Example (Creating pebibyte sizes)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// For extremely large data processing scenarios
const massiveDataset = FileSystem.PiB(2) // 2 PiB
// This would typically be used in enterprise/cloud scenarios
yield* Console.log(`Processing ${massiveDataset} bytes of data`)
// Such large files would require specialized streaming
const stream = fs.stream("massive-dataset.bin", {
chunkSize: FileSystem.GiB(1), // 1 GiB chunks
offset: FileSystem.TiB(100) // Start from 100 TiB offset
})
})export const const PiB: (n: number) => SizeCreates a Size representing pebibytes (1024⁵ bytes).
Details
Converts a number of pebibytes to the equivalent size in bytes.
Uses binary pebibytes (1,125,899,906,842,624 bytes) rather than decimal petabytes.
This function uses BigInt arithmetic to handle the very large numbers involved.
Example (Creating pebibyte sizes)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// For extremely large data processing scenarios
const massiveDataset = FileSystem.PiB(2) // 2 PiB
// This would typically be used in enterprise/cloud scenarios
yield* Console.log(`Processing ${massiveDataset} bytes of data`)
// Such large files would require specialized streaming
const stream = fs.stream("massive-dataset.bin", {
chunkSize: FileSystem.GiB(1), // 1 GiB chunks
offset: FileSystem.TiB(100) // Start from 100 TiB offset
})
})
PiB = (n: numbern: 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 => const Size: (bytes: SizeInput) => SizeCreates 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(n: numbern) * const bigintPiB: bigintbigintPiB)