New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-streamable-file

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-streamable-file

Cross platform symbol upload tool

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

bugsplat-github-banner-basic-outline

BugSplat

Crash and error reporting built for busy developers.


ℹ️ This implementation is for Node.js prior to 19.8. For 19.8 or newer, please use fs.openAsBlob.

node-streamable-file

This repo contains a convenience function for creating a File object that can be appended by FormData and uploaded via Fetch using a ReadableStream. Node.js has a maximum https://nodejs.org/api/buffer.html size of 2 GB. Uploading files that are larger than the maximum Buffer size will result in an ERR_FS_FILE_TOO_LARGE error. The implementation in this repo was inspired by this StackOverflow post.

⚙️ Installation

Install this package

npm i node-streamable-file

If you're using Node.js prior to 18.13, you'll also need to install a polyfill for File.

npm i @web-std/file

🧑‍💻 Usage

Import createStreamableFile from node-streamable-file and open from node:fs/promises.

import { createStreamableFile } from 'node-streamable-file';
import { open } from 'node:fs/promises';

Call open with the path to your file to create a FileHandle and pass it to createStreamableFile. The result of createStreamableFile can be appended to a FormData object and uploaded via Fetch. Be sure to call handle.close when you're done with the file.

const path = 'path/to/file.txt';
const name = basename(path);
const handle = await open(path);
const file = await createStreamableFile(name, handle);

const formData = new FormData();
formData.append('file', file, name);

await fetch(url, {
  method: 'POST',
  body: formData
});

await handle.close();

💥 Known Issues

You might run into the following

Argument of type 'File' is not assignable to parameter of type 'Blob'

This issue is a result of a bug in TypeScript. You can read more about it here and here. You can silence this error by casting to unknown and then to Blob.

formData.append('file', file as unknown as Blob);

Alternatively, the warning can be fixed by setting "skipLibCheck": true, in your tsconfig.json file.

🐛 About

BugSplat is a software crash and error reporting service with support for Node.js, Electron, Web applications, and many more. BugSplat automatically captures critical diagnostic data such as stack traces, log files, and other runtime information. BugSplat also provides automated incident notifications, a convenient dashboard for monitoring trends and prioritizing engineering efforts, and integrations with popular development tools to maximize productivity and ship more profitable software.

Keywords

node

FAQs

Package last updated on 06 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts