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

@jonathanlurie/bufferqueue

v0.1.3

Published

multilevel priority queue for downloading stuff from browser

Downloads

18

Readme

BufferQueue

The point of this JS library is to prioritise the download of a large number of binary files. It leverages the logic of a priority queue with multiple levels of priority. If N is the number of priority level you want, then 0 will be the highest priority and n-1 will be the lowest.

Each level is a first in first out list and each element is identified by its URL.

Install

npm install --save @jonathanlurie/bufferqueue

Usage

Instanciate the main object:

let myBufferQ = new bufferqueue.BufferQueue({
  priorityLevels: 5, // the number of priority level, N (default: 4)
  concurentDownloads: 4, // the number of concurrent downloads you allow. (Chrome allows a max of 6) (default: 3)
  httpSettings: {} // object containing the http header and other stuff (default: {})
})

To know more about the 'httpSettings' object, refer to the init object from Request documentation.

Since downloading file is an asynchronous process in Javascript, BufferQueue relies on custom events of different kinds:

  • added: when a file is just being added to the queue
myBufferQ.on('added', function(url, priority){
  // do something with it
})
  • removed: when a file is just being removed to the queue, without having started to get downloaded
myBufferQ.on('removed', function(url){
  // do something with it
})
  • reseted: When the whole priority queue has be reseted
myBufferQ.on('reseted', function(){
  // do something with it
})
  • downloading: when the download of a file is starting
myBufferQ.on('downloading', function(url){
  // do something with it
})
  • failed: when the download of a file has failed
myBufferQ.on('failed', function(url, error){
  // do something with it
})
  • aborted: when the download of a file has been explicitly aborted by the user
myBufferQ.on('aborted', function(url){
  // do something with it
})
  • success: when is a file download is completed successfully. buffer is an ArrayBuffer and time is the download time is in millisecond (you can then compute the actual download rate)
myBufferQ.on('success', function(url, buffer, time){
  // do something with it
})

In addition to events, an instance of BufferQueue has some methods:

myBufferQ.add(
  'http://example.com/some-file', // URL
  0 // level of priority
)

The other other methods can be found in the documentation.