Detect empty input and throw a helpful error (#2687)

This commit is contained in:
Jacob
2021-05-03 04:29:51 -04:00
committed by GitHub
parent a688468378
commit 52e4543d31
4 changed files with 20 additions and 12 deletions

View File

@@ -30,9 +30,15 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
inputDescriptor.file = input;
} else if (is.buffer(input)) {
// Buffer
if (input.length === 0) {
throw Error('Input Buffer is empty');
}
inputDescriptor.buffer = input;
} else if (is.uint8Array(input)) {
// Uint8Array or Uint8ClampedArray
if (input.length === 0) {
throw Error('Input Bit Array is empty');
}
inputDescriptor.buffer = Buffer.from(input.buffer);
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
// Plain Object descriptor, e.g. create