Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uwdata/flechette",
"version": "2.2.2",
"version": "2.2.3",
"description": "Fast, lightweight access to Apache Arrow data.",
"keywords": [
"arrow",
Expand Down
5 changes: 2 additions & 3 deletions src/decode/decode-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @import { ArrowData, Version_ } from '../types.js'
*/
import { MAGIC, MessageHeader, Version } from '../constants.js';
import { isArrayBufferLike } from '../util/arrays.js';
import { readInt16, readInt32, readObject } from '../util/read.js';
import { decodeBlocks } from './block.js';
import { decodeMessage } from './message.js';
Expand All @@ -25,9 +26,7 @@ import { decodeSchema } from './schema.js';
* @returns {import('../types.js').ArrowData}
*/
export function decodeIPC(data) {
const source = data instanceof ArrayBuffer || data instanceof SharedArrayBuffer
? new Uint8Array(data)
: data;
const source = isArrayBufferLike(data) ? new Uint8Array(data) : data;
Copy link
Member

@domoritz domoritz Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could invert the check, which may be a bit simpler.

export function decodeIPC(data) {
  const source = Array.isArray(data) || ArrayBuffer.isView(data)
    ? data
    : new Uint8Array(data);
  return source instanceof Uint8Array && isArrowFileFormat(source)
    ? decodeIPCFile(source)
    : decodeIPCStream(source);
}

return source instanceof Uint8Array && isArrowFileFormat(source)
? decodeIPCFile(source)
: decodeIPCStream(source);
Expand Down
12 changes: 12 additions & 0 deletions src/util/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export const int64Array = BigInt64Array;
export const float32Array = Float32Array;
export const float64Array = Float64Array;

/**
* Check if an input value is an ArrayBuffer or SharedArrayBuffer.
* @param {unknown} data
* @returns {data is ArrayBufferLike}
*/
export function isArrayBufferLike(data) {
return data instanceof ArrayBuffer || (
typeof SharedArrayBuffer !== 'undefined' &&
data instanceof SharedArrayBuffer
);
}

/**
* Return the appropriate typed array constructor for the given
* integer type metadata.
Expand Down