Skip to content

Commit bcd7f3a

Browse files
committed
add test
1 parent 5b5e5e0 commit bcd7f3a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/unit/io.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ describe('Input/output', function () {
182182
assert.strictEqual(info.height, 1);
183183
});
184184

185+
it('Read from Uint8ClampedArray with byteOffset and output to Buffer', async () => {
186+
// since a Uint8ClampedArray is the same as Uint8Array but clamps the values
187+
// between 0-255 it seemed good to add this also
188+
const uint8array = Uint8ClampedArray.from([0, 0, 0, 255, 255, 255, 0, 0, 0, 255, 255, 255]);
189+
const uint8ArrayWithByteOffset = new Uint8ClampedArray(uint8array.buffer, 3, 6);
190+
const { data, info } = await sharp(uint8ArrayWithByteOffset, {
191+
raw: {
192+
width: 2,
193+
height: 1,
194+
channels: 3
195+
}
196+
}).toBuffer({ resolveWithObject: true });
197+
198+
assert.deepStrictEqual(Uint8ClampedArray.from([255, 255, 255, 0, 0, 0]), new Uint8ClampedArray(data));
199+
assert.strictEqual(info.width, 2);
200+
assert.strictEqual(info.height, 1);
201+
});
202+
185203
it('Stream should emit info event', function (done) {
186204
const readable = fs.createReadStream(fixtures.inputJpg);
187205
const writable = fs.createWriteStream(outputJpg);

0 commit comments

Comments
 (0)