HiraokaHyperTools / msgreader

40 stars 9 forks source link

Using datastream-js as base for DataStream #3

Closed sveisvei closed 2 years ago

sveisvei commented 4 years ago

I was on my way writing exactly this module, and found your module half way through the job. Thanx for sharing.

One suggestion, is to the module datastream-js.


import DataStreamJS from "datastream-js";

export class DataStream extends DataStreamJS {
  /**
       Reads a 16-bit int from the DataStream with the offset

       @param {number} offset The offset.
       @return {number} The read number.
       */
  readShort(offset: number) {
    this.seek(offset);
    return this.readInt16();
  }

  /**
       Reads an 8-bit int from the DataStream with the offset.

       @param {number} offset The offset.
       @return {number} The read number.
       */
  readByte(offset: number): number {
    this.seek(offset);
    return this.readInt8();
  }

  /**
       Reads a 32-bit int from the DataStream with the offset.

       @param {number} offset The offset.
       @return {number} The read number.
       */
  readInt(offset: number) {
    this.seek(offset);
    return this.readInt32();
  }

  /**
       Read UCS-2 string of desired length and offset from the DataStream.

       @param {number} offset The offset.
       @param {number} length The length of the string to read.
       @return {string} The read string.
       */
  readStringAt(offset: number, length: number) {
    this.seek(offset);
    return this.readUCS2String(length);
  }
}
kenjiuno commented 4 years ago

Hi @sveisvei Thanks for looking at this msgreader!

Perhaps you might have been noticed... Original msgreader was also what I had been looking for my purpose. I have fixed some parts for my company's job. So I don't understand the most part of implementation so much.

I'll check it in my free time, thanks!