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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@huggingface/blob

v0.0.2

Published

Utilities to convert URLs and files to Blobs, internally used by Hugging Face libs

Downloads

71

Readme

🤗 Hugging Face Blobs

Utilities to convert a string or URL to a Blob object, whether it represents a local file or a remote URL.

fetch already returns a Blob object for remote URLs, but it loads the entire file in memory. This utility makes ad-hoc http range requests when calling .slice() on the blob.

Install

pnpm add @huggingface/blob

npm add @huggingface/blob

yarn add @huggingface/blob

Deno

// esm.sh
import { FileBlob } from "https://esm.sh/@huggingface/blob/FileBlob";
import { WebBlob } from "https://esm.sh/@huggingface/blob/WebBlob";
import { createBlob } from "https://esm.sh/@huggingface/blob";
// or npm:
import { FileBlob } from "npm:@huggingface/blob/FileBlob";
import { WebBlob } from "npm:@huggingface/blob/WebBlob";
import { createBlob } from "npm:@huggingface/blob";

Usage

import { FileBlob } from "@huggingface/blob/FileBlob";
import { WebBlob } from "@huggingface/blob/WebBlob";
import { createBlob } from "@huggingface/blob";

const fileBlob = await FileBlob.create("path/to/file");
const webBlob = await WebBlob.create("https://url/to/file");

const blob = await createBlob("..."); // Automatically detects if it's a file or web URL

API

createBlob

Creates a Blob object from a string or URL. Automatically detects if it's a file or web URL.

await createBlob("...", {
  /**
   * Custom fetch function to use, in case it resolves to a Web Blob.
   * 
   * Useful for adding headers, etc.
   */
  fetch: ...,
});

### FileBlob

```ts
await FileBlob.create("path/to/file");
await FileBlob.create(new URL("file:///path/to/file"));

WebBlob

Creates a Blob object from a URL. If the file is less than 1MB (as indicated by the Content-Length header), by default it will be cached in memory in entirety upon blob creation.

This class is useful for large files that do not need to be loaded all at once in memory, as it makes range requests for the data.

await WebBlob.create("https://url/to/file");
await WebBlob.create(new URL("https://url/to/file"));

await WebBlob.create("https://url/to/file", {
  /**
   * Custom fetch function to use. Useful for adding headers, etc.
   */
  fetch: ...,
  /**
   * If the file is less than the specified size, it will be cached in memory in entirety upon blob creation,
   * instead of doing range requests for the data.
   * 
   * @default 1_000_000
   */
  cacheBelow: ...
})