(n: number): SizeCreates a Size representing mebibytes (1024² bytes).
Details
Converts a number of mebibytes to the equivalent size in bytes. Uses binary mebibytes (1,048,576 bytes) rather than decimal megabytes.
Example (Creating mebibyte sizes)
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Set a 10 MiB chunk size for large file operations
const largeChunkSize = FileSystem.MiB(10)
const stream = fs.stream("video.mp4", {
chunkSize: largeChunkSize
})
// Check if file is larger than 100 MiB
const stats = yield* fs.stat("archive.zip")
const maxSize = FileSystem.MiB(100)
if (stats.size > maxSize) {
yield* Effect.log("File is very large!")
}
})export const const MiB: (n: number) => SizeCreates a Size representing mebibytes (1024² bytes).
Details
Converts a number of mebibytes to the equivalent size in bytes.
Uses binary mebibytes (1,048,576 bytes) rather than decimal megabytes.
Example (Creating mebibyte sizes)
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Set a 10 MiB chunk size for large file operations
const largeChunkSize = FileSystem.MiB(10)
const stream = fs.stream("video.mp4", {
chunkSize: largeChunkSize
})
// Check if file is larger than 100 MiB
const stats = yield* fs.stat("archive.zip")
const maxSize = FileSystem.MiB(100)
if (stats.size > maxSize) {
yield* Effect.log("File is very large!")
}
})
MiB = (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(n: numbern * 1024 * 1024)