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 🙏

© 2025 – Pkg Stats / Ryan Hefner

form-data-web-stream

v0.0.1

Published

A multi-part streaming FormData implementation that uses Web Streams

Readme

form-data-web-stream

A modern web streams compatible "multipart/form-data" encoder. Inspired by https://github.com/form-data/form-data but simplified and updated to only use modern web standards. Unlike the built in FormData object, this implementation can support full streaming, where the data being uploaded is never fully loaded into memory as a Blob.

Basic Usage

import FormDataWebStream from "form-data-web-stream"

const sourceRes = await fetch("https://example.com/source")
if (!sourceRes.ok) {
  throw new Error("Fetch failed: " + (await sourceRes.text()))
}

const data = new FormDataWebStream()
data.appendString("my-field", "hello world")
data.appendStream("my-file", sourceRes.body, {
  contentType: "text/plain",
  filename: "sample-file.txt",
  // You only need to specify `byteLength` if you plan to call `getByteLength` later
  byteLength: parseInt(sourceRes.headers.get("content-length"), 10),
})

const response = await fetch("https://example.com/destination", {
  method: "POST",
  headers: {
    "Content-Length": `${data.getByteLength()}`,
    "Content-Type": data.getContentTypeHeader(),
  },
  body: data.toStream(),
  duplex: "half",
})

console.log(await response.text())

Usage with node.js streams

This library only uses Web streams, so node.js streams need to be converted using Readable.toWeb before passing them into this library.

import { createReadStream } from "fs"
import { Readable } from "stream"
import FormDataWebStream from "form-data-web-stream"

const data = new FormDataWebStream()
data.appendString("my-field", "hello world")
data.appendStream("my-file", Readable.toWeb(createReadStream("sample-file.txt")), {
  contentType: "text/plain",
  filename: "sample-file.txt",
})

const response = await fetch("https://example.com/destination", {
  method: "POST",
  headers: {
    "Content-Type": data.getContentTypeHeader(),
  },
  body: data.toStream(),
  duplex: "half",
})

console.log(await response.text())

API

FormDataWebStream.appendString(field: string, value: string, options?: AppendOptions)

Append a string value to the form data.

FormDataWebStream.appendData(field: string, value: Uint8Array, options?: AppendOptions)

Append a binary value to the form data.

FormDataWebStream.appendStream(field: string, value: ReadableStream, options?: AppendStreamOptions)

Append a stream to the form data. Make sure you specify options.byteLength if you want to later call .getByteLength().

FormDataWebStream.hasByteLength()

Returns true if a byte length is available. This will be false if any calls to appendStream did not include a byteLength option.

FormDataWebStream.getByteLength()

Returns the byte length of the entire stream, if available. This will throw an error if any calls to appendStream did not include a byteLength option.

FormDataWebStream.getContentTypeHeader()

Returns the header to use as the Content-Type in your request.

FormDataWebStream.toStream()

Returns a ReadableStream<Uint8Array> representing the body of the request.