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

animated-gif-detector

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

animated-gif-detector - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

test/files/09_24_14_Better_Together_GC_Event_FD.gif

29

index.js
var Writable = require('stream').Writable
, util = require('util')
, inherits = require('inherits')
// GIF CONSTANTS. source => http://www.onicos.com/staff/iz/formats/gif.html
, BLOCK_TERMINATOR = { value: new Buffer('00') }
, EXTENSION_INTRODUCER = {
value: new Buffer('21')
, head: 0
, tail: 1
}
, GRAPHIC_CONTROL_LABEL = {
value: new Buffer('f9')
, head: 1
, tail: 2
}
, DELAY_TIME = {
value: 0 // if there's a delay time, it's animated! 0 means false positive.
, head: 3
, tail: 5
}
;
util.inherits(AnimatedGifDetector, Writable);
inherits(AnimatedGifDetector, Writable);
function AnimatedGifDetector(buffer, options) {

@@ -16,5 +33,6 @@ Writable.call(this, options);

for (var i = 0; i < buffer.length; i++) {
result = pointer == '00' &&
buffer.toString('hex', i, i + 1) == '21' &&
buffer.toString('hex', i + 1, i + 2) == 'f9';
result = pointer == BLOCK_TERMINATOR.value &&
buffer.toString('hex', i + EXTENSION_INTRODUCER.head, i + EXTENSION_INTRODUCER.tail) == EXTENSION_INTRODUCER.value &&
buffer.toString('hex', i + GRAPHIC_CONTROL_LABEL.head, i + GRAPHIC_CONTROL_LABEL.tail) == GRAPHIC_CONTROL_LABEL.value &&
buffer.toString('hex', i + DELAY_TIME.head, i + DELAY_TIME.tail) > DELAY_TIME.value;
pointer = buffer.toString('hex', i, i + 1);

@@ -24,2 +42,3 @@ if (result)

}
return { pointer: pointer, animated: result };

@@ -26,0 +45,0 @@ }

6

package.json
{
"name": "animated-gif-detector",
"version": "0.3.0",
"version": "1.0.0",
"description": "Detect animated GIFs from JavaScript buffers.",

@@ -17,3 +17,5 @@ "main": "index.js",

},
"dependencies": {},
"dependencies": {
"inherits": "^2.0.1"
},
"repository": {

@@ -20,0 +22,0 @@ "type": "git",

@@ -79,2 +79,146 @@ var path = require('path')

test('postcard.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'postcard.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('1E3A0FFF2F0ED7F3DD8DAE5CC461494E.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', '1E3A0FFF2F0ED7F3DD8DAE5CC461494E.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('09_24_14_Better_Together_GC_Event_FD.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', '09_24_14_Better_Together_GC_Event_FD.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('21.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', '21.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('calendar_265x230.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'calendar_265x230.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('2026556_rw_nl_160X250.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', '2026556_rw_nl_160X250.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('connections.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'connections.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('block-7.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'block-7.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('PSP14_728-x-90_HOUZZ.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'PSP14_728-x-90_HOUZZ.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('daily-idea-header.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'daily-idea-header.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('b_cc_email14.gif', function(t) {
var file = path.join(process.cwd(), 'test', 'files', 'b_cc_email14.gif')
, result = false
;
fs.createReadStream(file)
.pipe(animated())
.once('animated', function() { result = true; })
.on('finish', function() {
t.notOk(result, 'is NOT animated');
t.end();
});
});
test('sync => true', function(t) {

@@ -81,0 +225,0 @@ var filePath = path.join(process.cwd(), 'test', 'files', 'example.gif');

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