Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Buffer undefined reference error #704

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions modules/io/src/common/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export function getDataContainer(data) {
return null;
}

if (data instanceof Buffer || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
if (
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
data instanceof ArrayBuffer ||
ArrayBuffer.isView(data)
) {
return 'binary';
}

Expand Down Expand Up @@ -329,7 +333,7 @@ function isJSONStringTypeArray(arr) {

// Buffer.slice() does not make a copy, but we need one since
// we call reverse()
if (lastChars instanceof Buffer) {
if (typeof Buffer !== 'undefined' && lastChars instanceof Buffer) {
lastChars = Buffer.from(lastChars);
}

Expand Down
8 changes: 4 additions & 4 deletions modules/io/src/common/xviz-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ export class XVIZData {
let data = this._data;
switch (this._dataFormat) {
case XVIZ_FORMAT.BINARY_GLB:
if (data instanceof Buffer) {
if (typeof Buffer !== 'undefined' && data instanceof Buffer) {
data = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
msg = parseBinaryXVIZ(data);
break;
case XVIZ_FORMAT.BINARY_PBE:
if (data instanceof Buffer) {
if (typeof Buffer !== 'undefined' && data instanceof Buffer) {
data = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
msg = parseBinaryXVIZ(data, this._opts);
break;
case XVIZ_FORMAT.JSON_BUFFER:
let jsonString = null;
if (data instanceof Buffer) {
if (typeof Buffer !== 'undefined' && data instanceof Buffer) {
// Default to utf8 encoding
jsonString = data.toString();
} else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
Expand Down Expand Up @@ -154,7 +154,7 @@ export class XVIZData {
let data = this._data;
switch (getDataContainer(data)) {
case 'binary':
if (data instanceof Buffer) {
if (typeof Buffer !== 'undefined' && data instanceof Buffer) {
data = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}

Expand Down