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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@agen/buffers

v0.2.0

Published

Transforms string to buffers and other way around

Downloads

4

Readme

@agen/buffers

Transform individual elements from parent generator to/from Buffer instances.

There are following methods in this package:

  • buffersFromStrings - transforms sequence of encoded strings to corresponding sequence of Buffer instances
  • buffersToLines - transforms sequence of Buffer instances to sequence of strings; each buffer is decoded and splitted to individual lines
  • fixedSizeBuffers - sequence of Buffers with different length is transformed to a sequence of buffers with the same length

buffersFromStrings method

This method accepts the following parameters:

  • generator - asynchronous generator providing inidvidual strings
  • enc - encoding used to transform strings to corresponding buffers; UTF-8 by default

It returns an asynchronous generator providing Buffer instances.

Example:


const bufs = require('@agen/buffers');
const list = [
  'item-0',
  'item-1',
  'item-2',
  'item-3',
  'item-4',
  'item-5',
  'item-6',
  'item-7'
]
for await (let b of bufs.buffersFromStrings(list)) {
  console.log('-', b, Buffer.isBuffer(b));
}
// Will print
// - <Buffer 69 74 65 6d 2d 30> true
// - <Buffer 69 74 65 6d 2d 31> true
// - <Buffer 69 74 65 6d 2d 32> true
// - <Buffer 69 74 65 6d 2d 33> true
// - <Buffer 69 74 65 6d 2d 34> true
// - <Buffer 69 74 65 6d 2d 35> true
// - <Buffer 69 74 65 6d 2d 36> true
// - <Buffer 69 74 65 6d 2d 37> true

buffersToLines method

This method transforms Buffer instances to sequence of lines, encoded in these buffers. To transform Buffers to strings user can define custom encoding (UTF-8 is used by default).

Parameters:

  • generator - asynchronous generator providing Buffer instances
  • enc - encoding used to transform buffers to strings; UTF-8 by default

It returns an asynchronous generator providing individual lines.

Example:

  const bufs = require('@agen/buffers');

  // Sequence of Buffer instances
  const list = [
    'Lorem ipsum dolor sit amet, \nconsectetur adipiscing elit. \nPellentesque ',
    'vulputate tortor ac \ntortor placerat mattis. Cras auctor erat ut \nsem ',
    'varius, id eleifend felis dictum. \nAenean non lobortis leo.\n',
    'Morbi cursus vestibulum est sit amet sollicitudin. \nNunc laoreet metus ',
    'malesuada enim laoreet porttitor tincidunt a tellus. Quisque eget commodo ',
    'ipsum.\nSed aliquet iaculis erat, ut posuere dolor condimentum sit amet.'
  ].map(Buffer.from);

  for await (let str of bufs.buffersToLines(list)) {
    console.log('-', str);
  }

  // Will print:
  // - Lorem ipsum dolor sit amet,
  // - consectetur adipiscing elit.
  // - Pellentesque vulputate tortor ac
  // - tortor placerat mattis. Cras auctor erat ut
  // - sem varius, id eleifend felis dictum.
  // - Aenean non lobortis leo.
  // - Morbi cursus vestibulum est sit amet sollicitudin.
  // - Nunc laoreet metus malesuada enim laoreet porttitor tincidunt a tellus. Quisque eget commodo ipsum.
  // - Sed aliquet iaculis erat, ut posuere dolor condimentum sit amet.

fixedSizeBuffers method

This method transforms sequence of buffers of various sizes to buffers of the same size.

Parameters:

  • generator - asynchronous generator providing Buffer instances of various sizes
  • size - size of the resulting buffers

Example:

  const bufs = require('@agen/buffers');

  const list = [
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ',
    'vulputate tortor ac tortor placerat mattis. Cras auctor erat ut sem ',
    'varius, id eleifend felis dictum. Aenean non lobortis leo.',
    'Morbi cursus vestibulum est sit amet sollicitudin. Nunc laoreet metus ',
    'malesuada enim laoreet porttitor tincidunt a tellus. Quisque eget commodo ',
    'ipsum. Sed aliquet iaculis erat, ut posuere dolor condimentum sit amet.'
  ].map(Buffer.from);

  const bufLen = 30;
  for await (let b of bufs.fixedSizeBuffers(list, bufLen)) {
    console.log('-', b.toString());
  }

  // Will print:
  // - Lorem ipsum dolor sit amet, co
  // - nsectetur adipiscing elit. Pel
  // - lentesque vulputate tortor ac
  // - tortor placerat mattis. Cras a
  // - uctor erat ut sem varius, id e
  // - leifend felis dictum. Aenean n
  // - on lobortis leo.Morbi cursus v
  // - estibulum est sit amet sollici
  // - tudin. Nunc laoreet metus male
  // - suada enim laoreet porttitor t
  // - incidunt a tellus. Quisque ege
  // - t commodo ipsum. Sed aliquet i
  // - aculis erat, ut posuere dolor
  // - condimentum sit amet.