dataReader.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Interface for a data buffer
  3. */
  4. export interface IDataBuffer {
  5. /**
  6. * Reads bytes from the data buffer.
  7. * @param byteOffset The byte offset to read
  8. * @param byteLength The byte length to read
  9. * @returns A promise that resolves when the bytes are read
  10. */
  11. readAsync(byteOffset: number, byteLength: number): Promise<ArrayBufferView>;
  12. /**
  13. * The byte length of the buffer.
  14. */
  15. readonly byteLength: number;
  16. }
  17. /**
  18. * Utility class for reading from a data buffer
  19. */
  20. export declare class DataReader {
  21. /**
  22. * The data buffer associated with this data reader.
  23. */
  24. readonly buffer: IDataBuffer;
  25. /**
  26. * The current byte offset from the beginning of the data buffer.
  27. */
  28. byteOffset: number;
  29. private _dataView;
  30. private _dataByteOffset;
  31. /**
  32. * Constructor
  33. * @param buffer The buffer to read
  34. */
  35. constructor(buffer: IDataBuffer);
  36. /**
  37. * Loads the given byte length.
  38. * @param byteLength The byte length to load
  39. * @returns A promise that resolves when the load is complete
  40. */
  41. loadAsync(byteLength: number): Promise<void>;
  42. /**
  43. * Read a unsigned 32-bit integer from the currently loaded data range.
  44. * @returns The 32-bit integer read
  45. */
  46. readUint32(): number;
  47. /**
  48. * Read a byte array from the currently loaded data range.
  49. * @param byteLength The byte length to read
  50. * @returns The byte array read
  51. */
  52. readUint8Array(byteLength: number): Uint8Array;
  53. /**
  54. * Read a string from the currently loaded data range.
  55. * @param byteLength The byte length to read
  56. * @returns The string read
  57. */
  58. readString(byteLength: number): string;
  59. /**
  60. * Skips the given byte length the currently loaded data range.
  61. * @param byteLength The byte length to skip
  62. */
  63. skipBytes(byteLength: number): void;
  64. }