index.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // Type definitions for smart-buffer
  2. // Project: https://github.com/JoshGlazebrook/smart-buffer
  3. // Definitions by: Josh Glazebrook <https://github.com/JoshGlazebrook>
  4. declare class SmartBuffer {
  5. /**
  6. * Creates a new SmartBuffer instance (defaults to utf8 encoding)
  7. */
  8. constructor();
  9. /**
  10. * Creates a new SmartBuffer instance
  11. *
  12. * @param arg1 { Number } The size the underlying buffer instance should be instantiated to (defaults to 4096)
  13. * @param arg2 { String } The string encoding to use for reading/writing strings (defaults to utf8)
  14. */
  15. constructor(size: number, encoding?: string);
  16. /**
  17. * Creates a new SmartBuffer instance
  18. *
  19. * @param arg1 { String } The string encoding to use for reading/writing strings (defaults to utf8)
  20. */
  21. constructor(encoding?: string);
  22. /**
  23. * Creates a new SmartBuffer instance
  24. *
  25. * @param arg1 { Buffer } An existing buffer instance to copy to this smart buffer instance
  26. * @param arg2 { String } The string encoding to use for reading/writing strings (defaults to utf8)
  27. */
  28. constructor(buffer: Buffer, encoding?: string)
  29. // Signed number readers
  30. /**
  31. * Reads a 8-bit signed integer
  32. */
  33. readInt8(): number;
  34. /**
  35. * Reads a 16-bit signed integer (big endian)
  36. */
  37. readInt16BE(): number;
  38. /**
  39. * Reads a 16-bit signed integer (little endian)
  40. */
  41. readInt16LE(): number;
  42. /**
  43. * Reads a 32-bit signed integer (big endian)
  44. */
  45. readInt32BE(): number;
  46. /**
  47. * Reads a 32-bit signed integer (little endian)
  48. */
  49. readInt32LE(): number;
  50. // Unsigned number readers
  51. /**
  52. * Reads a 8-bit unsigned integer
  53. */
  54. readUInt8(): number;
  55. /**
  56. * Reads a 16-bit unsigned integer (big endian)
  57. */
  58. readUInt16BE(): number;
  59. /**
  60. * Reads a 16-bit unsigned integer (little endian)
  61. */
  62. readUInt16LE(): number;
  63. /**
  64. * Reads a 32-bit unsigned integer (big endian)
  65. */
  66. readUInt32BE(): number;
  67. /**
  68. * Reads a 32-bit unsigned integer (little endian)
  69. */
  70. readUInt32LE(): number;
  71. // Floating point readers
  72. /**
  73. * Reads a float (big endian)
  74. */
  75. readFloatBE(): number;
  76. /**
  77. * Reads a float (little endian)
  78. */
  79. readFloatLE(): number;
  80. /**
  81. * Reads a double (big endian)
  82. */
  83. readDoubleBE(): number;
  84. /**
  85. * Reads a double (little endian)
  86. */
  87. readDoubleLE(): number;
  88. // String readers
  89. /**
  90. * Reads a string
  91. *
  92. * @param length { Number } The length of the string to read
  93. * @param encoding { Number} The encoding to use (defaults to instance level encoding)
  94. */
  95. readString(length?: number, encoding?: string): string;
  96. /**
  97. * Reads a null terminated string
  98. *
  99. * @param encoding The encoding to use (defaults to instance level encoding)
  100. */
  101. readStringNT(encoding?: string): string;
  102. // Buffer readers
  103. /**
  104. * Reads binary data into a Buffer
  105. *
  106. * @param len { Number } The amount of data to read
  107. */
  108. readBuffer(len?: number): Buffer;
  109. /**
  110. * Reads null terminated binary data into a Buffer
  111. */
  112. readBufferNT(): Buffer;
  113. // Signed number writers
  114. /**
  115. * Writes a 8-bit signed integer value
  116. *
  117. * @param value { Number } The value to write to the buffer
  118. * @param offset { Number } The offset position to write the value to
  119. */
  120. writeInt8(value: number, offset?: number): this;
  121. /**
  122. * Writes a 16-bit signed integer (big endian) value
  123. *
  124. * @param value { Number } The value to write to the buffer
  125. * @param offset { Number } The offset position to write the value to
  126. */
  127. writeInt16BE(value: number, offset?: number): this;
  128. /**
  129. * Writes a 16-bit signed integer (little endian) value
  130. *
  131. * @param value { Number } The value to write to the buffer
  132. * @param offset { Number } The offset position to write the value to
  133. */
  134. writeInt16LE(value: number, offset?: number): this;
  135. /**
  136. * Writes a 32-bit signed integer (big endian) value
  137. *
  138. * @param value { Number } The value to write to the buffer
  139. * @param offset { Number } The offset position to write the value to
  140. */
  141. writeInt32BE(value: number, offset?: number): this;
  142. /**
  143. * Writes a 32-bit signed integer (little endian) value
  144. *
  145. * @param value { Number } The value to write to the buffer
  146. * @param offset { Number } The offset position to write the value to
  147. */
  148. writeInt32LE(value: number, offset?: number): this;
  149. // Unsigned number writers
  150. /**
  151. * Writes a 8-bit unsigned integer value
  152. *
  153. * @param value { Number } The value to write to the buffer
  154. * @param offset { Number } The offset position to write the value to
  155. */
  156. writeUInt8(value: number, offset?: number): this;
  157. /**
  158. * Writes a 16-bit unsigned integer (big endian) value
  159. *
  160. * @param value { Number } The value to write to the buffer
  161. * @param offset { Number } The offset position to write the value to
  162. */
  163. writeUInt16BE(value: number, offset?: number): this;
  164. /**
  165. * Writes a 16-bit unsigned integer (little endian) value
  166. *
  167. * @param value { Number } The value to write to the buffer
  168. * @param offset { Number } The offset position to write the value to
  169. */
  170. writeUInt16LE(value: number, offset?: number): this;
  171. /**
  172. * Writes a 32-bit unsigned integer (big endian) value
  173. *
  174. * @param value { Number } The value to write to the buffer
  175. * @param offset { Number } The offset position to write the value to
  176. */
  177. writeUInt32BE(value: number, offset?: number): this;
  178. /**
  179. * Writes a 32-bit unsigned integer (little endian) value
  180. *
  181. * @param value { Number } The value to write to the buffer
  182. * @param offset { Number } The offset position to write the value to
  183. */
  184. writeUInt32LE(value: number, offset?: number): this;
  185. // Floating point writers
  186. /**
  187. * Writes a float (big endian) value
  188. *
  189. * @param value { Number } The value to write to the buffer
  190. * @param offset { Number } The offset position to write the value to
  191. */
  192. writeFloatBE(value: number, offset?: number): this;
  193. /**
  194. * Writes a float (little endian) value
  195. *
  196. * @param value { Number } The value to write to the buffer
  197. * @param offset { Number } The offset position to write the value to
  198. */
  199. writeFloatLE(value: number, offset?: number): this;
  200. /**
  201. * Writes a double (big endian) value
  202. *
  203. * @param value { Number } The value to write to the buffer
  204. * @param offset { Number } The offset position to write the value to
  205. */
  206. writeDoubleBE(value: number, offset?: number): this;
  207. /**
  208. * Writes a double (little endian) value
  209. *
  210. * @param value { Number } The value to write to the buffer
  211. * @param offset { Number } The offset position to write the value to
  212. */
  213. writeDoubleLE(value: number, offset?: number): this;
  214. // String writers
  215. /**
  216. * Writes a string
  217. *
  218. * @param value { String } The value to write to the buffer
  219. * @param offset { Number } The offset position to write the value to
  220. */
  221. /**
  222. * Writes a string
  223. *
  224. * @param value { String } The value to write to the buffer
  225. * @param offset { String } The encoding to use when writing the string (defaults to instance level encoding)
  226. */
  227. /**
  228. * Writes a string
  229. *
  230. * @param value { String } The value to write to the buffer
  231. * @param offset { Number } The offset position to write the value to
  232. * @param encoding { String } The encoding to use when writing the string (defaults to instance level encoding)
  233. */
  234. writeString(value: string, offset?: number | string, encoding?: string): this;
  235. /**
  236. * Writes a null terminated string
  237. *
  238. * @param value { String } The value to write to the buffer
  239. * @param offset { Number } The offset position to write the value to
  240. */
  241. /**
  242. * Writes a null terminated string
  243. *
  244. * @param value { String } The value to write to the buffer
  245. * @param offset { String } The encoding to use when writing the string (defaults to instance level encoding)
  246. */
  247. /**
  248. * Writes a null terminated string
  249. *
  250. * @param value { String } The value to write to the buffer
  251. * @param offset { Number } The offset position to write the value to
  252. * @param encoding { String } The encoding to use when writing the string (defaults to instance level encoding)
  253. */
  254. writeStringNT(value: string, offset?: number | string, encoding?: string): this;
  255. // Buffer writers
  256. /**
  257. * Writes a Buffer
  258. *
  259. * @param value { Buffer } The Buffer to write to the smart buffer
  260. * @param offset { Number } The offset position to write the value to
  261. */
  262. writeBuffer(value: Buffer, offset?: number): this;
  263. /**
  264. * Writes a Buffer with null termination
  265. *
  266. * @param value { Buffer } The buffer to write to the smart buffer
  267. * @param offset { Number } The offset position to write the value to
  268. */
  269. writeBufferNT(value: Buffer, offset?: number): this;
  270. // Misc Functions
  271. /**
  272. * Clears the smart buffer
  273. */
  274. clear();
  275. /**
  276. * Gets the number of bytes that remain to be read
  277. */
  278. remaining(): number;
  279. /**
  280. * Increases the read offset position
  281. *
  282. * @param amount { Number } The amount to increase the read offset position by
  283. */
  284. skip(amount: number);
  285. /**
  286. * Changes the read offset position
  287. *
  288. * @param position { Number } The position to change the read offset to
  289. */
  290. skipTo(position: number);
  291. /**
  292. * Decreases the read offset position
  293. *
  294. * @param amount { Number } The amount to decrease the read offset position by
  295. */
  296. rewind(amount: number);
  297. /**
  298. * Gets the underlying Buffer instance
  299. */
  300. toBuffer(): Buffer;
  301. /**
  302. * Gets the string representation of the underlying Buffer
  303. *
  304. * @param encoding { String } The encoding to use (defaults to instance level encoding)
  305. */
  306. toString(encoding?: string): string;
  307. /**
  308. * Destroys the smart buffer instance
  309. */
  310. destroy();
  311. /**
  312. * Gets the current length of the smart buffer instance
  313. */
  314. length: number;
  315. }
  316. export = SmartBuffer;