Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-blob

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-blob

A Blob implementation in Node.js, originally from node-fetch.

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4M
decreased by-53.16%
Maintainers
3
Weekly downloads
 
Created

What is fetch-blob?

The fetch-blob npm package is a module that allows you to work with Blob data in a way that is consistent with the browser's Fetch API. It provides a way to create, read, and manipulate binary data in Node.js, which can be useful for tasks such as file uploads, image processing, and other operations that involve handling raw binary data.

What are fetch-blob's main functionalities?

Creating a Blob

This feature allows you to create a new Blob object from raw data. The example code creates a Blob containing the text 'Hello, world!' with a MIME type of 'text/plain'.

const { Blob } = require('fetch-blob');

const blob = new Blob(['Hello, world!'], { type: 'text/plain' });

Reading a Blob as text

This feature allows you to read the contents of a Blob as text. The example code reads the text from the Blob and logs it to the console.

const { Blob } = require('fetch-blob');

const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
blob.text().then((text) => {
  console.log(text); // Outputs: Hello, world!
});

Reading a Blob as a Buffer

This feature allows you to read the contents of a Blob as an ArrayBuffer, which can then be converted to a Node.js Buffer. The example code demonstrates how to convert the ArrayBuffer to a Buffer and log it to the console.

const { Blob } = require('fetch-blob');

const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
blob.arrayBuffer().then((buffer) => {
  const nodeBuffer = Buffer.from(buffer);
  console.log(nodeBuffer); // Outputs: <Buffer 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21>
});

Other packages similar to fetch-blob

Keywords

FAQs

Package last updated on 20 Apr 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc