Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit 70207c0

Browse files
bencefrIvanSanchez
authored andcommitted
Added typecheck of input of splitDescriptors() (#1)
* Added typecheck of input of splitDescriptors() * Simpler typecheck * Fixed most basic logic error
1 parent 426ccc8 commit 70207c0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/split-descriptors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
// Given a Uint8Array, returns an Array of Uint8Array
1010
// Each element of the resulting array is a subarray of the original Uint8Array.
1111
export default function splitDescriptors(bytes) {
12-
let len = bytes.length;
1312
const descs = [];
13+
if (!(bytes instanceof Uint8Array)) {
14+
return descs;
15+
}
16+
let len = bytes.length;
1417
let pointer = 0;
1518

1619
while (len > 0) {
@@ -38,4 +41,3 @@ The previous code should output:
3841
Uint8Array [ 4, 36, 2, 6 ],
3942
Uint8Array [ 5, 36, 6, 0, 1 ] ]
4043
*/
41-

0 commit comments

Comments
 (0)