packages/fs/README.md
Lazy, streaming filesystem utilities for JavaScript. This package provides utilities for working with files on the local filesystem using the LazyFile/ native File API.
LazyFile which matches the native File API and provides .stream(), .toFile(), and .toBlob() for converting to native types.npm i remix
import { openLazyFile } from 'remix/fs'
// Open a file from the filesystem
let lazyFile = openLazyFile('./path/to/file.json')
// The file is lazy - no data is read until you call lazyFile.text(), lazyFile.bytes(), etc.
let json = JSON.parse(await lazyFile.text())
// You can override file metadata
let customLazyFile = openLazyFile('./image.jpg', {
name: 'custom-name.jpg',
type: 'image/jpeg',
lastModified: Date.now(),
})
import { openLazyFile, writeFile } from 'remix/fs'
// Read a file and write it elsewhere
let lazyFile = openLazyFile('./source.txt')
await writeFile('./destination.txt', lazyFile)
// Write to an open file handle
import * as fsp from 'node:fs/promises'
let handle = await fsp.open('./destination.txt', 'w')
await writeFile(handle, lazyFile)
await handle.close()
lazy-file - Lazy, streaming Blob/File implementationfile-storage - Storage abstraction for filesSee LICENSE