mjpeg-consumer
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -0,0 +0,0 @@ var request = require("request"); |
@@ -0,10 +1,16 @@ | ||
var util = require('util'); | ||
var Transform = require('stream').Transform; | ||
require("buffertools"); | ||
var length = /Content-Length: \d+/; | ||
var lengthExpression = /Content-Length: \d+/i; | ||
var soi = new Buffer(2); | ||
soi.writeUInt16LE(0xd8ff, 0); | ||
var MjpegConsumer = function() { | ||
this.readable = true; | ||
this.writable = true; | ||
function MjpegConsumer(options) { | ||
if (!(this instanceof MjpegConsumer)) { | ||
return new MjpegConsumer(options); | ||
} | ||
Transform.call(this, options); | ||
this.bytesWritten = 0; | ||
@@ -14,12 +20,13 @@ this.totalBytes = 0; | ||
this.initialized = false; | ||
}; | ||
} | ||
require('util').inherits(MjpegConsumer, require('stream')); | ||
util.inherits(MjpegConsumer, Transform); | ||
MjpegConsumer.prototype.write = function(chunk) { | ||
MjpegConsumer.prototype._transform = function(chunk, encoding, done) { | ||
var len, start, initialBytes, remaining, soiIndex; | ||
if (chunk.length < this.totalBytes - this.bytesWritten) { | ||
if (chunk.length < this.totalBytes - this.bytesWritten) { | ||
chunk.copy(this.buffer, this.bytesWritten, 0, chunk.length); | ||
this.bytesWritten += chunk.length; | ||
done(); | ||
return; | ||
@@ -34,6 +41,6 @@ } | ||
len = length.exec(chunk); | ||
len = lengthExpression.exec(chunk); | ||
if (len) { | ||
if (this.initialized) { | ||
this.emit('data', this.buffer); | ||
this.push(this.buffer); | ||
} else { | ||
@@ -49,16 +56,10 @@ this.initialized = true; | ||
if (start !== -1) { | ||
initialBytes = (chunk.length - start); | ||
initialBytes = (chunk.length - start); | ||
chunk.copy(this.buffer, 0, start, chunk.length); | ||
this.bytesWritten += initialBytes; | ||
} | ||
}; | ||
MjpegConsumer.prototype.end = function(chunk) { | ||
this.writable = false; | ||
done(); | ||
}; | ||
MjpegConsumer.prototype.destroy = function() { | ||
this.writable = false; | ||
}; | ||
module.exports = MjpegConsumer; | ||
module.exports = MjpegConsumer; |
{ | ||
"name": "mjpeg-consumer", | ||
"version": "0.2.0", | ||
"description": "a nodejs stream implementation that consumes http mjpeg streams", | ||
"version": "0.3.0", | ||
"description": "a stream implementation that consumes http mjpeg streams and emits jpegs as buffers", | ||
"main": "index.js", | ||
@@ -13,2 +13,5 @@ "dependencies": { | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
@@ -15,0 +18,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
@@ -13,6 +13,8 @@ mjpeg-consumer | ||
###Objects### | ||
Requiring the `mjpeg-consumer` module returns a readable/writable stream implementation that takes an http stream of mjpegs and emits jpegs. | ||
Requiring the `mjpeg-consumer` module returns a readable/writable stream implementation that takes an http mjpeg stream and emits jpegs. | ||
var MjpegConsumer = require("mjpeg-consumer"); | ||
var consumer = new MjpegConsumer(); | ||
```javascript | ||
var MjpegConsumer = require("mjpeg-consumer"); | ||
var consumer = new MjpegConsumer(); | ||
``` | ||
@@ -23,12 +25,14 @@ ---------------------- | ||
var request = require("request"); | ||
var MjpegConsumer = require("mjpeg-consumer"); | ||
var FileOnWrite = require("file-on-write"); | ||
```javascript | ||
var request = require("request"); | ||
var MjpegConsumer = require("mjpeg-consumer"); | ||
var FileOnWrite = require("file-on-write"); | ||
var writer = new FileOnWrite({ | ||
path: './video', | ||
ext: '.jpg' | ||
}); | ||
var consumer = new MjpegConsumer(); | ||
var writer = new FileOnWrite({ | ||
path: './video', | ||
ext: '.jpg' | ||
}); | ||
var consumer = new MjpegConsumer(); | ||
request("http://192.168.1.2/videostream.cgi").pipe(consumer).pipe(shedder).pipe(writer); | ||
request("http://192.168.1.2/videostream.cgi").pipe(consumer).pipe(writer); | ||
``` |
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
66
37
4179