Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smart-buffer

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-buffer - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

1

build/smartbuffer.js

@@ -715,3 +715,2 @@ "use strict";

destroy() {
delete this.buff;
this.clear();

@@ -718,0 +717,0 @@ }

5

package.json
{
"name": "smart-buffer",
"version": "1.1.1",
"version": "1.1.2",
"description": "A smarter Buffer that keeps track of its own read and write positions while growing endlessly.",

@@ -44,4 +44,5 @@ "main": "build/smartbuffer.js",

"coverage": "istanbul cover node_modules/mocha/bin/_mocha recursive test",
"fullcoverage": "node_modules/.bin/istanbul -include-all-sources cover node_modules/mocha/bin/_mocha recursive test"
"fullcoverage": "node_modules/.bin/istanbul -include-all-sources cover node_modules/mocha/bin/_mocha recursive test",
"preinstall": "tsc -p ./"
}
}

@@ -17,3 +17,9 @@ smart-buffer [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/smart-buffer/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)

* Allows for inserting values at specific points in the internal Buffer.
* Built in TypeScript
* Type Definitions Provided
Requirements:
* Node v4.0+ is supported at this time. (Versions prior to 2.0 will work on node 0.10)
#### Note:

@@ -26,2 +32,6 @@ smart-buffer can be used for writing to an underlying buffer as well as reading from it. It however does not function correctly if you're mixing both read and write operations with each other.

or
`yarn install smart-buffer`
## Using smart-buffer

@@ -39,3 +49,3 @@

function createLoginPacket(username, password, age, country) {
var packet = new SmartBuffer();
let packet = new SmartBuffer();
packet.writeUInt16LE(0x0060); // Login Packet Type/ID

@@ -53,3 +63,3 @@ packet.writeStringNT(username);

```javascript
var login = createLoginPacket("Josh", "secret123", 22, "United States");
let login = createLoginPacket("Josh", "secret123", 22, "United States");

@@ -63,5 +73,5 @@ // <Buffer 60 00 1e 00 4a 6f 73 68 00 73 65 63 72 65 74 31 32 33 00 16 55 6e 69 74 65 64 20 53 74 61 74 65 73 00>

var reader = new SmartBuffer(login);
let reader = SmartBuffer.fromBuffer(login);
var logininfo = {
let logininfo = {
packetType: reader.readUInt16LE(),

@@ -91,18 +101,41 @@ packetLength: reader.readUInt16LE(),

smart-buffer has a few different constructor signatures you can use. By default, utf8 encoding is used, and the internal Buffer length will be 4096. When reading from a Buffer, smart-buffer does NOT make a copy of the Buffer. It reads from the Buffer it was given.
smart-buffer has a few different ways to construct an instance. Starting with version 2.0, the following factory methods are preffered.
```javascript
var SmartBuffer = require('smart-buffer');
let SmartBuffer = require('smart-buffer');
// Reading from an existing Buffer:
var reader = new SmartBuffer(buffer);
var reader = new SmartBuffer(buffer, 'ascii');
// Creating SmartBuffer from existing Buffer
let buff = SmartBuffer.fromBuffer(buffer); // Creates instance from buffer. (Uses default utf8 encoding)
let buff = SmartBuffer.fromBuffer(buffer, 'ascii'); // Creates instance from buffer with ascii encoding for Strings.
// Writing to a new Buffer:
var writer = new SmartBuffer(); // Defaults to utf8, 4096 length internal Buffer.
var writer = new SmartBuffer(1024); // Defaults to utf8, 1024 length internal Buffer.
var writer = new SmartBuffer('ascii'); // Sets to ascii encoding, 4096 length internal buffer.
var writer = new SmartBuffer(1024, 'ascii'); // Sets to ascii encoding, 1024 length internal buffer.
// Creating SmartBuffer with specified internal Buffer size.
let buff = SmartBuffer.fromSize(1024); // Creates instance with internal Buffer size of 1024.
let buff = SmartBuffer.fromSize(1024, 'utf8'); // Creates instance with intenral Buffer size of 1024, and utf8 encoding.
// Creating SmartBuffer with options object. This one specifies size and encoding.
let buff = SmartBuffer.fromOptions({
size: 1024,
encoding: 'ascii'
});
// Creating SmartBuffer with options object. This one specified an existing Buffer.
let buff = SmartBuffer.fromOptions({
buff: buffer
});
// Just want a regular SmartBuffer with all default options?
let buff = new SmartBuffer();
```
## Backwards Compatibility:
All constructors used prior to 2.0 still are supported. However it's not recommended to use these.
```javascript
let writer = new SmartBuffer(); // Defaults to utf8, 4096 length internal Buffer.
let writer = new SmartBuffer(1024); // Defaults to utf8, 1024 length internal Buffer.
let writer = new SmartBuffer('ascii'); // Sets to ascii encoding, 4096 length internal buffer.
let writer = new SmartBuffer(1024, 'ascii'); // Sets to ascii encoding, 1024 length internal buffer.
```
## Reading Data

@@ -133,4 +166,4 @@

```javascript
var reader = new SmartBuffer(somebuffer);
var num = reader.readInt8();
let reader = new SmartBuffer(somebuffer);
let num = reader.readInt8();
```

@@ -143,3 +176,3 @@

### SmartBuffer.readStringNT( [encoding] )
> `String` **String encoding to use** - Defaults to the encoding set in the constructor, or utf8.
> `String` **String encoding to use** - Defaults to the encoding set in the constructor.

@@ -150,5 +183,5 @@ returns `String`

### SmartBuffer.readString( [length], [encoding] )
### SmartBuffer.readString( [length] )
### SmartBuffer.readString( [encoding] )
### SmartBuffer.readString( [length], [encoding] )
> `Number` **Length of the string to read**

@@ -286,3 +319,3 @@

### SmartBuffer.skipTo( position )
### SmartBuffer.moveTo( position )
> `Number` **The point to skip the read position to**

@@ -304,7 +337,2 @@

### SmartBuffer.destroy()
Attempts to destroy the smart-buffer.
returns this
## Properties

@@ -311,0 +339,0 @@

@@ -142,3 +142,3 @@ var SmartBuffer = require('../build/smartbuffer');

describe('Constructing with factory methods', function () {
let originalBuffer = new Buffer(10);
var originalBuffer = new Buffer(10);

@@ -521,6 +521,2 @@ var sbuff1 = SmartBuffer.fromBuffer(originalBuffer);

});
it('Should have no internal buff property when buffer is destroyed', function () {
assert.notProperty(writer, 'buff');
});
});

@@ -527,0 +523,0 @@

@@ -28,2 +28,4 @@ /// <reference types="node" />

* @param encoding { BufferEncoding } The string encoding to use for reading/writing strings (defaults to utf8)
*
* @deprecated The .fromXXX() factory methods are now preferred over the new instantiator method.
*/

@@ -36,2 +38,4 @@ constructor(size: number, encoding?: BufferEncoding);

* @param encoding { BufferEncoding } The string encoding to use for reading/writing strings (defaults to utf8)
*
* @deprecated The .fromXXX() factory methods are now preferred over the new instantiator method.
*/

@@ -45,2 +49,4 @@ constructor(encoding?: BufferEncoding);

* @param encoding { BufferEncoding } The string encoding to use for reading/writing strings (defaults to utf8)
*
* @deprecated The .fromXXX() factory methods are now preferred over the new instantiator method.
*/

@@ -53,2 +59,3 @@ constructor(buff: Buffer, encoding?: string);

* @param options { SmartBufferOptions } The SmartBufferOptions settings to use when creating the SmartBuffer instance.
*
*/

@@ -107,3 +114,3 @@ constructor(options: SmartBufferOptions);

* @param func { Function(offset: number, offset?) => number} The function to write data on the internal Buffer with.
* @param byteSize { Number } The numer of bytes written.
* @param byteSize { Number } The number of bytes written.
* @param value { Number } The number value to write.

@@ -110,0 +117,0 @@ * @param offset { Number } the offset to write the number at.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc