length-prefixed-stream

WebJar for length-prefixed-stream

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

length-prefixed-stream
Last Version

Last Version

1.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

length-prefixed-stream
WebJar for length-prefixed-stream
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mafintosh/length-prefixed-stream

Download length-prefixed-stream

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/length-prefixed-stream/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>length-prefixed-stream</artifactId>
    <version>1.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/length-prefixed-stream/
implementation 'org.webjars.npm:length-prefixed-stream:1.6.0'
// https://jarcasting.com/artifacts/org.webjars.npm/length-prefixed-stream/
implementation ("org.webjars.npm:length-prefixed-stream:1.6.0")
'org.webjars.npm:length-prefixed-stream:jar:1.6.0'
<dependency org="org.webjars.npm" name="length-prefixed-stream" rev="1.6.0">
  <artifact name="length-prefixed-stream" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='length-prefixed-stream', version='1.6.0')
)
libraryDependencies += "org.webjars.npm" % "length-prefixed-stream" % "1.6.0"
[org.webjars.npm/length-prefixed-stream "1.6.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : buffer-alloc-unsafe jar [1.0.0,2)
org.webjars.npm : readable-stream jar [2.0.0,3)
org.webjars.npm : varint jar [5.0.0,6)

Project Modules

There are no modules declared in this project.

length-prefixed-stream

Streaming equivalent of length-prefixed-message. This module allow you to send Buffers with a varint length prefix to ensure that they will arrive unpartioned

npm install length-prefixed-stream

build status

Usage

var lpstream = require('length-prefixed-stream')

var encode = lpstream.encode() // create an encode stream to send data
var decode = lpstream.decode() // create an decode stream to receive data

encode.write('hello world') // send "hello world"

decode.on('data', function(data) {
  console.log(data.toString()) // will always print "hello world"
})

encode.pipe(decode) // for testing just pipe to our selves

Encoding format

This library encodes each chunks as follows:

<length-of-chunk-1> <chunk-1> <length-of-chunk-2> <chunk-2> …

The length of the following chunk is encoded using varint, which follows the protobuf-style varint encoding.

As an example, we're going to encode two ASCII chunks:

1st chunk:
68 65 79                            hey
2nd chunk:
68 65 6c 6c 6f 20 77 6f 72 6c 64    hello world

Encoded using length-prefixed-stream, they look like this:

03                                  varint-encoded length of 1st chunk
68 65 79                            1st chunk (3 bytes)
0b                                  varint-encoded length ()of 2nd chunk
68 65 6c 6c 6f 20 77 6f 72 6c 64    2nd chunk (11 bytes)

API

transformStream = lpstream.encode()

Creates a new encoder transform stream.

transformStream = lpstream.decode()

Creates a new decoder transform stream.

License

MIT

Versions

Version
1.6.0