Skip to content

Commit 81e8198

Browse files
committed
fix: fix at method error if node version is 14 or lower.
1 parent 3883b54 commit 81e8198

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/dynamicBuffer.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,19 @@ export class DynamicBuffer {
288288
if (!this.buffer || index >= this.used) {
289289
return undefined;
290290
}
291-
292291
if (index >= 0) {
293-
return this.buffer.at(index);
292+
return this.buffer[index];
293+
}
294+
if (typeof this.buffer.at === 'function') {
295+
return this.buffer.at(index - (this.size - this.length));
296+
}
297+
298+
// For Node 14 and lower versions.
299+
if (index + this.length < 0) {
300+
return undefined;
294301
}
295-
return this.buffer.at(index - (this.size - this.length));
302+
303+
return this.buffer[index + this.length];
296304
}
297305

298306
/**

0 commit comments

Comments
 (0)