mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support for ArrayBuffer input (#3548)
This commit is contained in:
@@ -150,6 +150,23 @@ describe('Input/output', function () {
|
||||
readable.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Read from ArrayBuffer and write to Buffer', async () => {
|
||||
const uint8array = Uint8Array.from([255, 255, 255, 0, 0, 0]);
|
||||
const arrayBuffer = new ArrayBuffer(uint8array.byteLength);
|
||||
new Uint8Array(arrayBuffer).set(uint8array);
|
||||
const { data, info } = await sharp(arrayBuffer, {
|
||||
raw: {
|
||||
width: 2,
|
||||
height: 1,
|
||||
channels: 3
|
||||
}
|
||||
}).toBuffer({ resolveWithObject: true });
|
||||
|
||||
assert.deepStrictEqual(uint8array, new Uint8Array(data));
|
||||
assert.strictEqual(info.width, 2);
|
||||
assert.strictEqual(info.height, 1);
|
||||
});
|
||||
|
||||
it('Read from Uint8Array and write to Buffer', async () => {
|
||||
const uint8array = Uint8Array.from([255, 255, 255, 0, 0, 0]);
|
||||
const { data, info } = await sharp(uint8array, {
|
||||
|
||||
@@ -11,6 +11,9 @@ describe('Raw pixel data', function () {
|
||||
assert.throws(function () {
|
||||
sharp(Buffer.from(''));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
sharp(new ArrayBuffer(0));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
sharp(new Uint8Array(0));
|
||||
}, /empty/);
|
||||
|
||||
Reference in New Issue
Block a user