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

mjpeg-consumer

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mjpeg-consumer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

33

lib/mjpeg-consumer.js

@@ -47,10 +47,20 @@ var util = require('util');

if (typeof start !== 'undefined' && start > -1) {
var hasStart = typeof start !== 'undefined' && start > -1;
var hasEnd = typeof end !== 'undefined' && end > -1;
if (hasStart) {
var bufEnd = chunk.length;
if (typeof end !== 'undefined' && end > -1) {
bufEnd = end;
if (hasEnd) {
bufEnd = end + eoi.length;
}
chunk.copy(this.buffer, 0, start, bufEnd);
this.bytesWritten = chunk.length - start;
this.reading = true;
// If we have the eoi bytes, send the frame
if (hasEnd) {
this._sendFrame();
} else {
this.reading = true;
}
}

@@ -67,3 +77,3 @@ };

var bufStart = start > -1 ? start : 0;
var bufEnd = end > -1 ? end : chunk.length;
var bufEnd = end > -1 ? end + eoi.length : chunk.length;

@@ -75,4 +85,3 @@ chunk.copy(this.buffer, this.bytesWritten, bufStart, bufEnd);

if (end > -1 || this.bytesWritten === this.contentLength) {
this.reading = false;
this.push(this.buffer);
this._sendFrame();
} else {

@@ -83,2 +92,10 @@ this.reading = true;

/**
* Handle sending the frame to the next stream and resetting state
*/
MjpegConsumer.prototype._sendFrame = function() {
this.reading = false;
this.push(this.buffer);
};
MjpegConsumer.prototype._transform = function(chunk, encoding, done) {

@@ -94,3 +111,3 @@ var start = chunk.indexOf(soi);

if (len) {
this._initFrame(+len, chunk, start);
this._initFrame(+len, chunk, start, end);
}

@@ -97,0 +114,0 @@

{
"name": "mjpeg-consumer",
"version": "1.0.1",
"version": "1.0.2",
"description": "a stream implementation that consumes http mjpeg streams and emits jpegs as buffers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -98,1 +98,46 @@ var MjpegConsumer = (function(coverage) {

};
var chunkHeaders = new Buffer('Content-Type: image/jpeg\nContent-Length: '+ IMG.length + '\n\n');
var chunkBoundary = new Buffer(boundary + '\n');
function getTestConsumer(t) {
var consumer = new MjpegConsumer();
consumer.once('data', function (chunk) {
t.equal(chunk.length, IMG.length);
t.equal(this.bytesWritten, IMG.length);
t.deepEqual(chunk, IMG);
t.done();
});
return consumer;
}
module.exports.testOneChunk = function(t) {
var consumer = getTestConsumer(t);
var all = Buffer.concat([chunkBoundary, chunkHeaders, IMG]);
consumer.end(all);
};
module.exports.testTwoChunksFirst = function(t) {
var consumer = getTestConsumer(t);
var boundaryAndHeaders = Buffer.concat([chunkBoundary, chunkHeaders]);
consumer.write(boundaryAndHeaders);
consumer.end(IMG);
};
module.exports.testTwoChunksSecond = function(t) {
var consumer = getTestConsumer(t);
var headersAndImage = Buffer.concat([chunkHeaders, IMG]);
consumer.write(chunkBoundary);
consumer.end(headersAndImage);
};
module.exports.testThreeChunks = function(t) {
var consumer = getTestConsumer(t);
consumer.write(chunkBoundary);
consumer.write(chunkHeaders);
consumer.end(IMG);
};

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