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

buffer-codec

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-codec - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

test/misc-test.coffee

35

lib/buffer-codec.js

@@ -33,7 +33,21 @@ (function() {

module.exports = Codec = (function() {
var codecs;
Codec.bufferSize = 8192;
Codec.getBuffer = function(aBufferSize) {
if (!Codec.buffer || Codec.buffer.length < aBufferSize) {
aBufferSize || (aBufferSize = Codec.bufferSize);
Codec.buffer = new Buffer(aBufferSize);
Codec.bufferSize = aBufferSize;
}
return Codec.buffer;
};
Codec._codecs = {};
codecs = Codec._codecs;
function Codec(aCodecName, aBufferSize) {
var result;
if (isNumber(aCodecName)) {

@@ -49,3 +63,7 @@ aBufferSize = aCodecName;

} catch (_error) {}
return Codec._codecs[aCodecName.toLowerCase()];
result = codecs[aCodecName.toLowerCase()];
if (result && aBufferSize > 0) {
result.init(aBufferSize);
}
return result;
} else {

@@ -57,7 +75,7 @@ this.init(aBufferSize);

Codec.prototype.init = function(aBufferSize) {
if (aBufferSize == null) {
aBufferSize = Codec.bufferSize;
}
if (this._encodeBuffer) {
this.buffer = new Buffer(aBufferSize);
if (this._encodeBuffer || aBufferSize > 0) {
aBufferSize || (aBufferSize = Codec.bufferSize);
if (!this.buffer || aBufferSize > this.buffer.length) {
this.buffer = new Buffer(aBufferSize);
}
return this.bufferSize = aBufferSize;

@@ -151,3 +169,3 @@ }

Codec.register = function(aCodecClass, aParentCodecClass, aBufferSize) {
var codecName, codecs, lowerName;
var codecName, lowerName;
if (aParentCodecClass == null) {

@@ -159,3 +177,2 @@ aParentCodecClass = Codec;

lowerName = codecName.toLowerCase();
codecs = Codec._codecs;
if (isInheritedFrom(aCodecClass, Codec) && !codecs.hasOwnProperty(lowerName)) {

@@ -170,3 +187,3 @@ Codec[codecName] = aCodecClass;

Codec.unregister = function(aCodecName) {
return delete Codec._codecs[aCodecName.toLowerCase()];
return delete codecs[aCodecName.toLowerCase()];
};

@@ -173,0 +190,0 @@

{
"name": "buffer-codec",
"version": "0.9.0",
"version": "0.9.1",
"description": "add the codec ability to abstract-nosql database.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/snowyu/node-buffer-codec",

@@ -22,6 +22,6 @@ # AbstractCodec

* the default start is 0, end is buffer.length - start.
* isBuffer(): it's true if the Codec implenments \_encodeBuffer/\_decodeBuffer only
* if the Codec implenments \_encodeBuffer/\_decodeBuffer only.
* bufferSize: the default max interal buffer size to encodeString data.
* buffer: the interal buffer instance to encodeString data.
* buffer: the Buffer instance.
* it's avaiable only when constructor passed bufferSize argument or \_encodeBuffer implenmented only.
* bufferSize: the default max interal buffer size.
* isBuffer(): it's true if have a interal buffer.

@@ -72,9 +72,16 @@

# get the JsonCodec Class
JsonCodec = Codec['Json']
# get the global JsonCodec instance from the Codec
json=Codec('json')
json = Codec('json')
# or:
json = JsonCodec()
JsonCodec().should.be.equal Codec('json')
# create a new JsonCodec instance.
JsonCodec = Codec['Json']
json = new JsonCodec()
json2 = new JsonCodec()
json2.should.not.be.equal json

@@ -81,0 +88,0 @@ # reuse this buffer instead of create every once.

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