Filesystem utilities using the Web File API
npm install @remix-run/fsLazy, streaming filesystem utilities for JavaScript.
This package provides utilities for working with files on the local filesystem using the LazyFile/ native File API.
- Web Standards - Uses LazyFile which matches the native File API and provides .stream(), .toFile(), and .toBlob() for converting to native types.
- Seamless Node.js Compat - Works seamlessly with Node.js file descriptors and handles
Install from npm:
``sh`
npm install @remix-run/fs
`ts
import { openLazyFile } from '@remix-run/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(),
})
`
`ts
import { openLazyFile, writeFile } from '@remix-run/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 files
-
See LICENSE