Comparing version 0.0.6 to 0.0.7
43
index.js
@@ -0,3 +1,10 @@ | ||
/** | ||
* Default export `Struct`. | ||
*/ | ||
// export default Struct; | ||
module.exports = exports = Struct; | ||
function byteField(p, offset) { | ||
this.length = 1; | ||
this.offset = offset; | ||
this.get = function() { | ||
@@ -13,2 +20,3 @@ return p.buf[offset]; | ||
this.length = length; | ||
this.offset = offset; | ||
this.get = function() { | ||
@@ -24,2 +32,3 @@ return (p.buf[offset] > 0 ); | ||
this.length = length; | ||
this.offset = offset; | ||
@@ -92,6 +101,10 @@ function bec(cb) { | ||
function charField(p, offset, length, encoding) { | ||
this.length = length; | ||
this.encoding = encoding; | ||
this.get = function() { | ||
var result = p.buf.toString(this.encoding, offset, offset + length); | ||
var self = this; | ||
self.length = length; | ||
self.offset = offset; | ||
self.encoding = encoding; | ||
self.get = function() { | ||
if (!length) return; | ||
var result = p.buf.toString(self.encoding, offset, offset + length); | ||
var strlen = result.indexOf("\0"); | ||
@@ -104,7 +117,15 @@ if (strlen == -1) { | ||
} | ||
this.set = function(val) { | ||
self.set = function(val) { | ||
if (!length) return; | ||
/* | ||
// comment off these might be less rubust, but chars encoding | ||
// would be ok | ||
val += "\0"; | ||
if (val.length > length) | ||
val = val.substring(0, length); | ||
p.buf.write(val, offset, this.encoding); | ||
*/ | ||
// buf.write(string, [offset], [length], [encoding]) | ||
p.buf.write(val, offset, length, self.encoding); | ||
} | ||
@@ -115,2 +136,3 @@ } | ||
this.length = struct.length(); | ||
this.offset = offset; | ||
this.get = function() { | ||
@@ -140,2 +162,3 @@ return struct; | ||
this.length = as.length(); | ||
this.offset = offset; | ||
this.allocate = function() { | ||
@@ -269,3 +292,3 @@ as._setBuff(p.buf.slice(offset, offset + as.length())); | ||
this._setBuff = function(buff) { | ||
this._setBuff = this.setBuffer = function(buff) { | ||
priv.buf = buff; | ||
@@ -289,2 +312,6 @@ applyClosures(priv); | ||
this.getOffset = function(field){ | ||
if(priv.fields[field]) return priv.fields[field].offset; | ||
} | ||
this.clone = function() { | ||
@@ -367,3 +394,1 @@ var c = new Struct; | ||
} | ||
exports.Struct = Struct; |
{ "name" : "struct" | ||
, "version" : "v0.0.6" | ||
, "version" : "v0.0.7" | ||
, "description" : "Pack/Unpack multibyte binary values from/to buffers " | ||
@@ -4,0 +4,0 @@ , "author": "Denys Khanzhiyev" |
@@ -18,3 +18,3 @@ Struct | ||
var Struct = require('../index.js').Struct; | ||
var Struct = require('struct'); | ||
@@ -21,0 +21,0 @@ var Person = Struct() |
@@ -1,2 +0,2 @@ | ||
var Struct = require('../index.js').Struct; | ||
var Struct = require('../index.js'); | ||
@@ -40,2 +40,2 @@ var | ||
console.log(t2[0]-t2[1]); | ||
console.log(t3[0]-t3[1]); | ||
console.log(t3[0]-t3[1]); |
@@ -1,2 +0,2 @@ | ||
var Struct = require('../index.js').Struct; | ||
var Struct = require('../index.js'); | ||
@@ -3,0 +3,0 @@ var Person = Struct() |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
18328
407
8