Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 6488c53

Browse files
committed
Use sync version of zlib deflate method to compress png images
1 parent a1156fb commit 6488c53

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

lib/image/png.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class PNGImage {
114114
const imgData = new Buffer(pixelCount * colorByteSize);
115115
const alphaChannel = new Buffer(pixelCount);
116116

117-
let i = (p = (a = 0));
117+
let i = p = a = 0;
118118
const len = pixels.length;
119119
while (i < len) {
120120
imgData[p++] = pixels[i++];
@@ -123,22 +123,13 @@ class PNGImage {
123123
alphaChannel[a++] = pixels[i++];
124124
}
125125

126-
let done = 0;
127-
zlib.deflate(imgData, (err, imgData1) => {
128-
this.imgData = imgData1;
129-
if (err) { throw err; }
130-
if (++done === 2) { return this.finalize(); }
131-
});
132-
133-
return zlib.deflate(alphaChannel, (err, alphaChannel1) => {
134-
this.alphaChannel = alphaChannel1;
135-
if (err) { throw err; }
136-
if (++done === 2) { return this.finalize(); }
137-
});
126+
this.imgData = zlib.deflateSync(imgData);
127+
this.alphaChannel = zlib.deflateSync(alphaChannel);
128+
return this.finalize();
138129
});
139130
}
140131

141-
loadIndexedAlphaChannel(fn) {
132+
loadIndexedAlphaChannel() {
142133
const transparency = this.image.transparency.indexed;
143134
return this.image.decodePixels(pixels => {
144135
const alphaChannel = new Buffer(this.width * this.height);
@@ -148,11 +139,8 @@ class PNGImage {
148139
alphaChannel[i++] = transparency[pixels[j]];
149140
}
150141

151-
return zlib.deflate(alphaChannel, (err, alphaChannel1) => {
152-
this.alphaChannel = alphaChannel1;
153-
if (err) { throw err; }
154-
return this.finalize();
155-
});
142+
this.alphaChannel = zlib.deflateSync(alphaChannel);
143+
return this.finalize();
156144
});
157145
}
158146
}

0 commit comments

Comments
 (0)