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

stream-octet-frame

v0.0.3

Published

Uses octet counting to frame messages through a stream

Downloads

4

Readme

stream-octet-frame

Uses octet counting to frame data through a stream

Data sent using the method frame will be prefixed with the number of bytes in the data. All chunks recieved on the stream will be buffered until the full frame has been recieved, and then it will be emitted as a frame event.


var octetFrame = require('stream-octet-frame')
  , net = require('net')
;

var server = net.createServer(socket) {
    socket.on('frame', function (buf) {
        console.log('frame recieved: ', buf.toString());
    });
    
    octetFrame(socket, { maxFrameSize: 64 });
    
    socket.frame('write this frame to the socket');
});

Installation

npm install stream-octet-frame

Dependencies

none

API

octetFrame(stream, [options])

Adds frame function to stream and listens for octet framed data

options.maxFrameSize (default: 1024)

Maximum number of bytes in each frame

Maximum value is Maximum value is 4294967295 (Math.pow(2, 32) - 1, 4gb - 1byte)

This may also be set on the stream:

stream.maxFrameSize = 1024;

options.readable (default: true)

Set to true to buffer data into frames

options.writable (default: true)

Set to true to add a frame method to stream

options.frameEncoding

Readable stream - will call .toString(frameEncoding) on the frame buffer before emitting the frame event

Writable stream - will use as the default encoding when converting a string into a buffer. Specifying an encoding when calling frame will overwrite this value

This may also be set on the stream:

stream.frameEncoding = 'utf8';

stream.frame(data, [encoding])

Converts data to a buffer with encoding, frames the data, and write the frame and data to the stream

data - A string or buffer encoding - Encoding to use when converting data to a buffer. Overrides options.frameEncoding

Only available if stream is writable and options.writable is true

Events (emitted on the stream)

'frame'

Emitted when a full data frame has been received.

Arguments:

  • data - A Buffer containing the data frame. If options.frameEncoding is set, a String will be passes with the specified encoding

Limitations

  • Do not use stream.setEncoding() when using this to frame data. The encoding will try to convert the raw bytes into strings, mangling the octet count and data byte cound in the process. The stream docs suggest to always use setEncoding when reading the data as strings, but this is just to buffer parts of the data enough to properly encode multi-byte characters. When framing data, all of the data will be buffered and encoding should work as expected.
  • The stream will automatically start to be consumed when using this method.