finki-main
main
|
Last change
on this file since 62b2964 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago |
|
Project Handcraft Marketplace
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Rev | Line | |
|---|
| [62b2964] | 1 | "use strict";
|
|---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
|---|
| 3 | exports.BufferReader = void 0;
|
|---|
| 4 | class BufferReader {
|
|---|
| 5 | constructor(offset = 0) {
|
|---|
| 6 | this.offset = offset;
|
|---|
| 7 | this.buffer = Buffer.allocUnsafe(0);
|
|---|
| 8 | // TODO(bmc): support non-utf8 encoding?
|
|---|
| 9 | this.encoding = 'utf-8';
|
|---|
| 10 | }
|
|---|
| 11 | setBuffer(offset, buffer) {
|
|---|
| 12 | this.offset = offset;
|
|---|
| 13 | this.buffer = buffer;
|
|---|
| 14 | }
|
|---|
| 15 | int16() {
|
|---|
| 16 | const result = this.buffer.readInt16BE(this.offset);
|
|---|
| 17 | this.offset += 2;
|
|---|
| 18 | return result;
|
|---|
| 19 | }
|
|---|
| 20 | byte() {
|
|---|
| 21 | const result = this.buffer[this.offset];
|
|---|
| 22 | this.offset++;
|
|---|
| 23 | return result;
|
|---|
| 24 | }
|
|---|
| 25 | int32() {
|
|---|
| 26 | const result = this.buffer.readInt32BE(this.offset);
|
|---|
| 27 | this.offset += 4;
|
|---|
| 28 | return result;
|
|---|
| 29 | }
|
|---|
| 30 | uint32() {
|
|---|
| 31 | const result = this.buffer.readUInt32BE(this.offset);
|
|---|
| 32 | this.offset += 4;
|
|---|
| 33 | return result;
|
|---|
| 34 | }
|
|---|
| 35 | string(length) {
|
|---|
| 36 | const result = this.buffer.toString(this.encoding, this.offset, this.offset + length);
|
|---|
| 37 | this.offset += length;
|
|---|
| 38 | return result;
|
|---|
| 39 | }
|
|---|
| 40 | cstring() {
|
|---|
| 41 | const start = this.offset;
|
|---|
| 42 | let end = start;
|
|---|
| 43 | // eslint-disable-next-line no-empty
|
|---|
| 44 | while (this.buffer[end++]) { }
|
|---|
| 45 | this.offset = end;
|
|---|
| 46 | return this.buffer.toString(this.encoding, start, end - 1);
|
|---|
| 47 | }
|
|---|
| 48 | bytes(length) {
|
|---|
| 49 | const result = this.buffer.slice(this.offset, this.offset + length);
|
|---|
| 50 | this.offset += length;
|
|---|
| 51 | return result;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | exports.BufferReader = BufferReader;
|
|---|
| 55 | //# sourceMappingURL=buffer-reader.js.map |
|---|
Note:
See
TracBrowser
for help on using the repository browser.