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.0.1 to 0.1.0

65

index.js

@@ -12,13 +12,22 @@ var Writable = require('stream').Writable

var isAnimated = function(buffer, pointer) {
var result = false;
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';
pointer = buffer.toString('hex', i, i + 1);
if (result)
break;
}
return { pointer: pointer, animated: result };
}
AnimatedGifDetector.prototype._write = function(chunk, enc, next) {
this.buffer = Buffer.concat([this.buffer, chunk]);
var value1, value2;
for (var i = this.pointer; i < this.buffer.length; i++) {
value1 = this.buffer.toString('hex', i, i + 1);
value2 = this.buffer.toString('hex', i + 1, i + 2);
// console.log(this.pointer, value1, value2);
if (this.pointer == '00' && value1 == '21' && value2 == 'f9')
this.emit('animated');
this.pointer = value1;
}
this.buffer = Buffer.concat([this.buffer, chunk])
, result = isAnimated(this.buffer, this.pointer)
;
if (result.animated)
this.emit('animated');
this.pointer = result.pointer;
next();

@@ -28,38 +37,6 @@ };

AnimatedGifDetector.prototype.sync = function(buffer) {
var result = false;
for (var i = 0; i < this.buffer.length; i++) {
value = this.buffer.toString('hex', i, i + 1);
if (pointer == '00' && value == '21') {
result = true;
break;
}
pointer = value;
}
return result;
buffer = Buffer.isBuffer(buffer) ? buffer : new Buffer(buffer);
return isAnimated(buffer).animated;
};
/*
var fs = require('fs')
, headers = require('./lib/offsets').headers
, buffer = []
;
fs.createReadStream('./test/files/GifSample.gif')
.on('data', buffer.push.bind(buffer))
.on('end', function() {
// headers.reduce(function(memo, offset) {
// memo = offset.start + offset.length;
// var value = this.buffer.slice(offset.start, offset.start + offset.length)
// .toString(offset.encoding)
// ;
// console.log(offset.description, '=>', value);
// return memo;
// }, 0);
});
;
*/
module.exports = AnimatedGifDetector;
{
"name": "animated-gif-detector",
"version": "0.0.1",
"version": "0.1.0",
"description": "animated-gif-detector --- Detect animated GIFs from JavaScript buffers.",

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

@@ -82,3 +82,3 @@ var path = require('path')

var buffer = fs.readFileSync(filePath);
t.notOk(new A().sync(buffer), 'is animated');
t.ok(new A().sync(buffer), 'is animated');
t.end();

@@ -85,0 +85,0 @@ });

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