Giter VIP home page Giter VIP logo

conflux's Introduction

Conflux by Transcend

Conflux

Build and read zip files with whatwg streams in the browser.

/ˈkänˌfləks/ (noun) a flowing together of two or more streams



Build Status Known Vulnerabilities Code Coverage Netlify Status


Blazing Fast

  • 21.6 kB import
  • Uses streams, minimizing memory overhead

Examples

Usage

Importing Conflux

# With Yarn
yarn add @transcend-io/conflux

# With NPM
npm install --save @transcend-io/conflux
import Zip from "@transcend-io/conflux/write";

const { readable, writable } = new Zip();

Writing a ZIP

import Zip from "@transcend-io/conflux/write";
import streamSaver from "streamsaver";

// Set up conflux
const { readable, writable } = new Zip();
const writer = writable.getWriter();

// Set up streamsaver
const fileStream = streamSaver.createWriteStream("conflux.zip");

// Add a file
writer.write({
  name: "/cat.txt",
  lastModified: new Date(0),
  stream: () => new Response("mjau").body
});

readable.pipeTo(fileStream);

writer.close();

Incorporating other streams

(async () => {
  writer.write({
    name: "/cat.txt",
    lastModified: new Date(0),
    stream: () => new Response("mjau").body
  });

  const imgStream = await fetch(
    "https://s3-us-west-2.amazonaws.com/bencmbrook/Earth.jpg"
  ).then(r => r.body);

  writer.write({
    name: "/Earth.jpg",
    lastModified: new Date(0),
    stream: () => imgStream
  });

  readable.pipeTo(fileStream);

  writer.close();
})();

Reading ZIP files

import reader from "@transcend-io/conflux/read";

fetch("https://cdn.jsdelivr.net/gh/Stuk/jszip/test/ref/deflate.zip").then(
  async res => {
    const zip = await res.blob();
    for await (const entry of reader(zip)) {
      console.log(entry);
    }
  }
);

License

FOSSA Status

conflux's People

Contributors

bencmbrook avatar dependabot[bot] avatar eligrey avatar fossabot avatar jimmywarting avatar michaelfarrell76 avatar vincaslt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.