animated-gif-detector
Advanced tools
Comparing version 1.1.4 to 1.1.5
10
index.js
@@ -22,3 +22,2 @@ var Writable = require('stream').Writable | ||
this.buffer = new Buffer(0); | ||
this.isGIF = false; | ||
} | ||
@@ -50,10 +49,13 @@ | ||
if (this.buffer.length > 4) | ||
if (this.buffer.length > 4 && this.isGIF == undefined) | ||
this.isGIF = this.buffer.slice(0, 3).toString() === 'GIF'; | ||
// If it's the first chunk of stream we analyze and is not GIF, stop | ||
if (this.isGIF === false) | ||
return next(); | ||
return this.emit('finish'); | ||
if (animated) | ||
if (animated) { | ||
this.emit('animated'); | ||
return this.emit('finish'); | ||
} | ||
@@ -60,0 +62,0 @@ next(); |
{ | ||
"name": "animated-gif-detector", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Detect animated GIFs from JavaScript buffers.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var path = require('path') | ||
, fs = require('fs') | ||
, stream = require('stream') | ||
, test = require('tap').test | ||
@@ -278,2 +279,20 @@ , animated = require(path.join(process.cwd(), 'index')) | ||
test('streaming => infinite buffer', function(t) { | ||
var readable = new stream.Readable; | ||
var timeout = setTimeout(function() { | ||
throw new Error('it did not exit the infinite buffer'); | ||
}, 200); | ||
readable._read = function() { | ||
this.push(new Buffer('infinite')); // this readable never ends | ||
}; | ||
readable | ||
.pipe(animated()) | ||
.on('finish', function() { | ||
clearTimeout(timeout); | ||
t.ok(true, 'it ended despite infinite buffer'); | ||
t.end(); | ||
}) | ||
; | ||
}); | ||
test('sync => false (non-image)', function(t) { | ||
@@ -280,0 +299,0 @@ var filePath = path.join(process.cwd(), 'test', 'files', 'file.txt'); |
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
2513765
346