File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 22 * @import { ArrowData, Version_ } from '../types.js'
33 */
44import { MAGIC , MessageHeader , Version } from '../constants.js' ;
5+ import { isArrayBufferLike } from '../util/arrays.js' ;
56import { readInt16 , readInt32 , readObject } from '../util/read.js' ;
67import { decodeBlocks } from './block.js' ;
78import { decodeMessage } from './message.js' ;
@@ -25,9 +26,7 @@ import { decodeSchema } from './schema.js';
2526 * @returns {import('../types.js').ArrowData }
2627 */
2728export function decodeIPC ( data ) {
28- const source = data instanceof ArrayBuffer || data instanceof SharedArrayBuffer
29- ? new Uint8Array ( data )
30- : data ;
29+ const source = isArrayBufferLike ( data ) ? new Uint8Array ( data ) : data ;
3130 return source instanceof Uint8Array && isArrowFileFormat ( source )
3231 ? decodeIPCFile ( source )
3332 : decodeIPCStream ( source ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ export const int64Array = BigInt64Array;
1212export const float32Array = Float32Array ;
1313export const float64Array = Float64Array ;
1414
15+ /**
16+ * Check if an input value is an ArrayBuffer or SharedArrayBuffer.
17+ * @param {unknown } data
18+ * @returns {data is ArrayBufferLike }
19+ */
20+ export function isArrayBufferLike ( data ) {
21+ return data instanceof ArrayBuffer || (
22+ typeof SharedArrayBuffer !== 'undefined' &&
23+ data instanceof SharedArrayBuffer
24+ ) ;
25+ }
26+
1527/**
1628 * Return the appropriate typed array constructor for the given
1729 * integer type metadata.
You can’t perform that action at this time.
0 commit comments