chunky-dump-reader
Advanced tools
Comparing version 1.0.0 to 1.0.1
56
index.js
@@ -1,18 +0,50 @@ | ||
const binary = require('binary') | ||
const util = require('util') | ||
const { Writable } = require('stream') | ||
const zlib = require('zlib') | ||
// width (int32bs), height (int32bs), spp (int32bs), renderTime (int64bs) | ||
const expectedHeaderCount = 4 + 4 + 4 + 8 | ||
function DumpCheckStream (options) { | ||
Writable.call(this, options) | ||
this.headerCount = 0 | ||
this.header = [] | ||
} | ||
util.inherits(DumpCheckStream, Writable) | ||
DumpCheckStream.prototype._write = function (chunk, enc, cb) { | ||
if (this.headerCount < expectedHeaderCount) { | ||
const headerPart = chunk.slice(0, Math.max(0, expectedHeaderCount - this.headerCount)) | ||
if (headerPart.length > 0) { | ||
this.headerCount += headerPart.length | ||
this.header.push(headerPart) | ||
} | ||
} | ||
if (this.headerCount === expectedHeaderCount && this.width == null && this.height == null) { | ||
const header = this.header[0].length >= 20 ? this.header[0] : Buffer.concat(this.header) | ||
this.width = header.readInt32BE(0) | ||
this.height = header.readInt32BE(4) | ||
this.spp = header.readInt32BE(8) | ||
this.renderTime = header.readIntBE(12, 8, true) | ||
this.valid = true | ||
this.emit('dump header') | ||
} | ||
cb() | ||
} | ||
const getDumpInfo = (dumpStream) => new Promise((resolve, reject) => { | ||
let tapped = false | ||
const ws = binary() | ||
.word32bs('width') | ||
.word32bs('height') | ||
.word32bs('spp') | ||
.word64bs('renderTime') | ||
.tap((vars) => { | ||
tapped = true | ||
resolve(vars) | ||
const ws = new DumpCheckStream() | ||
ws.on('dump header', () => { | ||
resolve({ | ||
width: ws.width, | ||
height: ws.height, | ||
spp: ws.spp, | ||
renderTime: ws.renderTime | ||
}) | ||
}) | ||
dumpStream.on('end', () => { | ||
if (!tapped) { | ||
reject(new Error('Unexpected end of dump stream')) | ||
if (!ws.valid) { | ||
reject(new Error('Invalid dump stream')) | ||
} | ||
@@ -19,0 +51,0 @@ }) |
{ | ||
"name": "chunky-dump-reader", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A tiny util module to read Chunky dumps.", | ||
@@ -9,5 +9,2 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"binary": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
@@ -14,0 +11,0 @@ "chai": "^3.5.0", |
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
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
120950
0
74
- Removedbinary@^0.3.0
- Removedbinary@0.3.0(transitive)
- Removedbuffers@0.1.1(transitive)
- Removedchainsaw@0.1.0(transitive)
- Removedtraverse@0.3.9(transitive)