Socket
Book a DemoInstallSign in
Socket

@miroculus/anaconda-chunks-transfer

Package Overview
Dependencies
Maintainers
8
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miroculus/anaconda-chunks-transfer

Create chunks from a string or buffer for wire-transfer

4.0.0
latest
Source
npmnpm
Version published
Maintainers
8
Created
Source

Chunks Transfer

This utility prepares a given buffer to be transfered in chunks, probably through the network. Useful when you want to transfer large files using a custom protocol.

Usage

You will need to use the library on a server and a client. On the server you will generate the chunks with the metadata and then send them one by one to the client.

In this example we will be using the functions publishToClient and onMessageFromServer which should be your custom transfer methods.

e.g.:

server.js

const { createChunks } = require('@miroculus/anaconda-chunks-transfer')

const content = 'superbigstring....'

const chunks = createChunks({
  content: Buffer.from(content), // Complete buffer you want to transfer
  chunkSize: 12 // maximum amount of bytes of data a chunk should contain
})

chunks.forEach((chunk) => {
  publishToClient(chunk)
})
const { createReceiver } = require('@miroculus/anaconda-chunks-transfer')

let receiver = null

onMessageFromServer((chunk) => {
  if (!receiver) {
    const { id, total } = chunk
    receiver = createReceiver({ id, total })
  }

  receiver.addChunk(chunk)

  // The message has been completely received
  if (receiver.done()) {
    console.log(receiver.toString())
  }
})

Keywords

buffer

FAQs

Package last updated on 24 Jan 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.