npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@remix-run/lazy-file

v5.0.2

Published

Lazy, streaming files for JavaScript

Readme

lazy-file

A lazy, streaming Blob/File implementation for JavaScript.

It allows you to easily create Blob-like and File-like objects that defer reading their contents until needed, which is ideal for situations where a file's contents do not fit in memory all at once. When file contents are read, they are streamed to avoid buffering.

Features

  • Deferred Loading - Blob/file contents loaded on demand to minimize memory usage
  • Familiar Interface - LazyBlob and LazyFile implement the same interface as native Blob and File
  • Easy Conversion - Convert to native ReadableStream with .stream(), or to native Blob/File with .toBlob() and .toFile()
  • Standard Constructors - Accepts all the same content types as the original Blob() and File() constructors
  • Slice Support - Supports Blob.slice(), even on streaming content

Why You Need This

JavaScript's File API is useful, but it's not a great fit for streaming server environments where you don't want to buffer file contents. In particular, the File() constructor requires the contents of a file to be supplied up front when the object is first created, like this:

let file = new File(['hello world'], 'hello.txt', { type: 'text/plain' })

A LazyFile improves this model by accepting an additional content type in its constructor: LazyContent.

let lazyContent: LazyContent = {
  /* See below for usage */
}
let lazyFile = new LazyFile(lazyContent, 'hello.txt', { type: 'text/plain' })

All other File functionality works as you'd expect.

Installation

npm i remix

Usage

The low-level API can be used to create a LazyFile that streams content from anywhere:

import { type LazyContent, LazyFile } from 'remix/lazy-file'

let content: LazyContent = {
  // The total length of this file in bytes.
  byteLength: 100000,
  // A function that provides a stream of data for the file contents,
  // beginning at the `start` index and ending at `end`.
  stream(start, end) {
    // ... read the file contents from somewhere and return a ReadableStream
    return new ReadableStream({
      start(controller) {
        controller.enqueue('X'.repeat(100000).slice(start, end))
        controller.close()
      },
    })
  },
}

let lazyFile = new LazyFile(content, 'example.txt', { type: 'text/plain' })
await lazyFile.arrayBuffer() // ArrayBuffer of the file's content
lazyFile.name // "example.txt"
lazyFile.type // "text/plain"

All file contents are read on-demand and nothing is ever buffered unless you explicitly call .toFile() or .toBlob().

Streaming Content

Use .stream() to get a ReadableStream for Response and other streaming APIs:

import { openLazyFile } from 'remix/fs'

let lazyFile = openLazyFile('./large-video.mp4')

let response = new Response(lazyFile.stream(), {
  headers: {
    'Content-Type': lazyFile.type,
    'Content-Length': String(lazyFile.size),
  },
})

Converting to Native File/Blob

For non-streaming APIs that require a complete File or Blob (e.g. FormData), use .toFile() or .toBlob().

let lazyFile = openLazyFile('./document.pdf')
let realFile = await lazyFile.toFile()

let formData = new FormData()
formData.append('document', realFile)

Note: .toFile() and .toBlob() read the entire file into memory. Only use these for non-streaming APIs that require a complete File or Blob (e.g. FormData). Always prefer .stream() if possible.

Related Packages

  • fs - Filesystem utilities for reading and writing files using the Web File API
  • file-storage - Storage abstraction for files on disk or in memory

License

See LICENSE