animated-gif-detector
Advanced tools
Comparing version 0.1.1 to 0.2.0
12
index.js
@@ -9,3 +9,4 @@ var Writable = require('stream').Writable | ||
this.buffer = buffer || new Buffer(0); | ||
this.pointer = 0; // | ||
this.pointer = 0; | ||
this.isGIF = false; | ||
} | ||
@@ -30,2 +31,9 @@ | ||
; | ||
if (this.buffer.length > 4) | ||
this.isGIF = this.buffer.slice(0, 3).toString() === 'GIF'; | ||
if (this.isGIF === false) | ||
return next(); | ||
if (result.animated) | ||
@@ -39,2 +47,4 @@ this.emit('animated'); | ||
buffer = Buffer.isBuffer(buffer) ? buffer : new Buffer(buffer); | ||
if (buffer.slice(0, 3).toString() !== 'GIF') | ||
return false; | ||
return isAnimated(buffer).animated; | ||
@@ -41,0 +51,0 @@ }; |
{ | ||
"name": "animated-gif-detector", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Detect animated GIFs from JavaScript buffers.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -93,4 +93,4 @@ var path = require('path') | ||
test('sync => false (non-GIF)', function(t) { | ||
var filePath = path.join(process.cwd(), 'test', 'files', '240px-Felis_silvestris_silvestris_small_gradual_decrease_of_quality.png'); | ||
test('sync => false (non-GIF: PNG)', function(t) { | ||
var filePath = path.join(process.cwd(), 'test', 'files', 'Physical-Representations-of-Data.png'); | ||
var buffer = fs.readFileSync(filePath); | ||
@@ -101,2 +101,16 @@ t.notOk(new A().sync(buffer), 'is NOT animated'); | ||
test('streaming => false (non-GIF: PNG)', function(t) { | ||
var filePath = path.join(process.cwd(), 'test', 'files', 'Physical-Representations-of-Data.png') | ||
, animated = false | ||
; | ||
fs.createReadStream(filePath) | ||
.pipe(new A) | ||
.once('animated', function() { animated = true; }) | ||
.on('finish', function() { | ||
t.notOk(animated, 'is animated'); | ||
t.end(); | ||
}) | ||
; | ||
}); | ||
test('sync => false (non-image)', function(t) { | ||
@@ -103,0 +117,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
1127874
14
150