Socket
Socket
Sign inDemoInstall

pngjs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pngjs - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

lib/packer-async.js

66

lib/packer.js
'use strict';
var util = require('util');
var Stream = require('stream');
var zlib = require('zlib');
var filter = require('./filter-pack');
var constants = require('./constants');
var CrcStream = require('./crc');
var constants = require('./constants');
var bitPacker = require('./bitpacker');
var filter = require('./filter-pack');
var zlib = require('zlib');
var Packer = module.exports = function(options) {
Stream.call(this);
this._options = options;

@@ -30,17 +26,17 @@

}
};
this.readable = true;
Packer.prototype.getDeflateOptions = function() {
return {
chunkSize: this._options.deflateChunkSize,
level: this._options.deflateLevel,
strategy: this._options.deflateStrategy
};
};
util.inherits(Packer, Stream);
Packer.prototype.createDeflate = function() {
return this._options.deflateFactory(this.getDeflateOptions());
};
Packer.prototype.pack = function(data, width, height, gamma) {
// Signature
this.emit('data', new Buffer(constants.PNG_SIGNATURE));
this.emit('data', this._packIHDR(width, height, this._options.bitDepth, this._options.colorType));
if (gamma) {
this.emit('data', this._packGAMA(gamma));
}
Packer.prototype.filterData = function(data, width, height) {
// convert to correct format for filtering (e.g. right bpp and bit depth)

@@ -52,21 +48,3 @@ var packedData = bitPacker(data, width, height, this._options);

var filteredData = filter(packedData, width, height, this._options, bpp);
// compress it
var deflate = this._options.deflateFactory({
chunkSize: this._options.deflateChunkSize,
level: this._options.deflateLevel,
strategy: this._options.deflateStrategy
});
deflate.on('error', this.emit.bind(this, 'error'));
deflate.on('data', function(compressedData) {
this.emit('data', this._packIDAT(compressedData));
}.bind(this));
deflate.on('end', function() {
this.emit('data', this._packIEND());
this.emit('end');
}.bind(this));
deflate.end(filteredData);
return filteredData;
};

@@ -90,3 +68,3 @@

Packer.prototype._packGAMA = function(gamma) {
Packer.prototype.packGAMA = function(gamma) {
var buf = new Buffer(4);

@@ -97,3 +75,3 @@ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);

Packer.prototype._packIHDR = function(width, height, bitDepth, colorType) {
Packer.prototype.packIHDR = function(width, height) {

@@ -103,4 +81,4 @@ var buf = new Buffer(13);

buf.writeUInt32BE(height, 4);
buf[8] = bitDepth; // Bit depth
buf[9] = colorType; // colorType
buf[8] = this._options.bitDepth; // Bit depth
buf[9] = this._options.colorType; // colorType
buf[10] = 0; // compression

@@ -113,8 +91,8 @@ buf[11] = 0; // filter

Packer.prototype._packIDAT = function(data) {
Packer.prototype.packIDAT = function(data) {
return this._packChunk(constants.TYPE_IDAT, data);
};
Packer.prototype._packIEND = function() {
Packer.prototype.packIEND = function() {
return this._packChunk(constants.TYPE_IEND, null);
};
};

@@ -5,2 +5,3 @@ 'use strict';

var parse = require('./parser-sync');
var pack = require('./packer-sync');

@@ -12,1 +13,6 @@

};
exports.write = function(png) {
return pack(png);
};

@@ -6,3 +6,3 @@ 'use strict';

var Parser = require('./parser-async');
var Packer = require('./packer');
var Packer = require('./packer-async');
var PNGSync = require('./png-sync');

@@ -9,0 +9,0 @@

{
"name": "pngjs",
"version": "2.1.0",
"version": "2.2.0",
"description": "PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.",

@@ -8,2 +8,3 @@ "contributors": [

"Gaurav Mali",
"Gusts Kaksis",
"Kuba Niegowski",

@@ -10,0 +11,0 @@ "Luke Page",

@@ -33,5 +33,4 @@ [![Build Status](https://travis-ci.org/lukeapage/pngjs.svg?branch=master)](https://travis-ci.org/lukeapage/pngjs) [![Build status](https://ci.appveyor.com/api/projects/status/tb8418jql1trkntd/branch/master?svg=true)](https://ci.appveyor.com/project/lukeapage/pngjs2/branch/master) [![Coverage Status](https://coveralls.io/repos/lukeapage/pngjs2/badge.svg?branch=master&service=github)](https://coveralls.io/github/lukeapage/pngjs2?branch=master) [![npm version](https://badge.fury.io/js/pngjs.svg)](http://badge.fury.io/js/pngjs)

---------|--------------|------|-------|--------|-----------|-----------|-------|---------|--------
pngjs v2 | pngjs | Read | Yes | Yes | Yes | Yes | Yes | Yes | Yes
pngjs | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
node-png | pngjs | No | Yes | No | No | No | Hidden| Yes | Manual
pngjs | | No | Yes | No | No | No | Hidden| Yes | Manual
png-coder| pngjs | No | Yes | Yes | No | No | Hidden| Yes | Manual

@@ -249,2 +248,13 @@ pngparse | | No | Yes | No | Yes | No | No | No | Yes

### PNG.sync.write(png)
Take a PNG image and returns a buffer. The properties on the image include the meta data and `data` as per the async API above.
```
var data = fs.readFileSync('in.png');
var png = PNG.sync.read(data);
var buffer = PNG.sync.write(png);
fs.writeFileSync('out.png', buffer);
```
### PNG.adjustGamma(src)

@@ -264,2 +274,7 @@

### 2.2.0 - 04/12/2015
- Add sync write api
- Fix newfile example
- Correct comparison table
### 2.1.0 - 28/10/2015

@@ -266,0 +281,0 @@ - rename package to pngjs

Sorry, the diff of this file is not supported yet

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