BufferList.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. export type BufferListAcceptedTypes =
  2. | Buffer
  3. | BufferList
  4. | Uint8Array
  5. | BufferListAcceptedTypes[]
  6. | string
  7. | number;
  8. export interface BufferListConstructor {
  9. new (initData?: BufferListAcceptedTypes): BufferList;
  10. (initData?: BufferListAcceptedTypes): BufferList;
  11. /**
  12. * Determines if the passed object is a BufferList. It will return true
  13. * if the passed object is an instance of BufferList or BufferListStream
  14. * and false otherwise.
  15. *
  16. * N.B. this won't return true for BufferList or BufferListStream instances
  17. * created by versions of this library before this static method was added.
  18. *
  19. * @param other
  20. */
  21. isBufferList(other: unknown): boolean;
  22. }
  23. interface BufferList {
  24. prototype: Object
  25. /**
  26. * Get the length of the list in bytes. This is the sum of the lengths
  27. * of all of the buffers contained in the list, minus any initial offset
  28. * for a semi-consumed buffer at the beginning. Should accurately
  29. * represent the total number of bytes that can be read from the list.
  30. */
  31. length: number;
  32. /**
  33. * Adds an additional buffer or BufferList to the internal list.
  34. * this is returned so it can be chained.
  35. *
  36. * @param buffer
  37. */
  38. append(buffer: BufferListAcceptedTypes): this;
  39. /**
  40. * Adds an additional buffer or BufferList at the beginning of the internal list.
  41. * this is returned so it can be chained.
  42. *
  43. * @param buffer
  44. */
  45. prepend(buffer: BufferListAcceptedTypes): this;
  46. /**
  47. * Will return the byte at the specified index.
  48. * @param index
  49. */
  50. get(index: number): number;
  51. /**
  52. * Returns a new Buffer object containing the bytes within the
  53. * range specified. Both start and end are optional and will
  54. * default to the beginning and end of the list respectively.
  55. *
  56. * If the requested range spans a single internal buffer then a
  57. * slice of that buffer will be returned which shares the original
  58. * memory range of that Buffer. If the range spans multiple buffers
  59. * then copy operations will likely occur to give you a uniform Buffer.
  60. *
  61. * @param start
  62. * @param end
  63. */
  64. slice(start?: number, end?: number): Buffer;
  65. /**
  66. * Returns a new BufferList object containing the bytes within the
  67. * range specified. Both start and end are optional and will default
  68. * to the beginning and end of the list respectively.
  69. *
  70. * No copies will be performed. All buffers in the result share
  71. * memory with the original list.
  72. *
  73. * @param start
  74. * @param end
  75. */
  76. shallowSlice(start?: number, end?: number): this;
  77. /**
  78. * Copies the content of the list in the `dest` buffer, starting from
  79. * `destStart` and containing the bytes within the range specified
  80. * with `srcStart` to `srcEnd`.
  81. *
  82. * `destStart`, `start` and `end` are optional and will default to the
  83. * beginning of the dest buffer, and the beginning and end of the
  84. * list respectively.
  85. *
  86. * @param dest
  87. * @param destStart
  88. * @param srcStart
  89. * @param srcEnd
  90. */
  91. copy(
  92. dest: Buffer,
  93. destStart?: number,
  94. srcStart?: number,
  95. srcEnd?: number
  96. ): Buffer;
  97. /**
  98. * Performs a shallow-copy of the list. The internal Buffers remains the
  99. * same, so if you change the underlying Buffers, the change will be
  100. * reflected in both the original and the duplicate.
  101. *
  102. * This method is needed if you want to call consume() or pipe() and
  103. * still keep the original list.
  104. *
  105. * @example
  106. *
  107. * ```js
  108. * var bl = new BufferListStream();
  109. * bl.append('hello');
  110. * bl.append(' world');
  111. * bl.append('\n');
  112. * bl.duplicate().pipe(process.stdout, { end: false });
  113. *
  114. * console.log(bl.toString())
  115. * ```
  116. */
  117. duplicate(): this;
  118. /**
  119. * Will shift bytes off the start of the list. The number of bytes
  120. * consumed don't need to line up with the sizes of the internal
  121. * Buffers—initial offsets will be calculated accordingly in order
  122. * to give you a consistent view of the data.
  123. *
  124. * @param bytes
  125. */
  126. consume(bytes?: number): void;
  127. /**
  128. * Will return a string representation of the buffer. The optional
  129. * `start` and `end` arguments are passed on to `slice()`, while
  130. * the encoding is passed on to `toString()` of the resulting Buffer.
  131. *
  132. * See the [`Buffer#toString()`](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end)
  133. * documentation for more information.
  134. *
  135. * @param encoding
  136. * @param start
  137. * @param end
  138. */
  139. toString(encoding?: string, start?: number, end?: number): string;
  140. /**
  141. * Will return the byte at the specified index. indexOf() method
  142. * returns the first index at which a given element can be found
  143. * in the BufferList, or -1 if it is not present.
  144. *
  145. * @param value
  146. * @param byteOffset
  147. * @param encoding
  148. */
  149. indexOf(
  150. value: string | number | Uint8Array | BufferList | Buffer,
  151. byteOffset?: number,
  152. encoding?: string
  153. ): number;
  154. /**
  155. * Will return the internal list of buffers.
  156. */
  157. getBuffers(): Buffer[];
  158. /**
  159. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  160. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  161. *
  162. * @param offset
  163. */
  164. readDoubleBE: Buffer['readDoubleBE'];
  165. /**
  166. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  167. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  168. *
  169. * @param offset
  170. */
  171. readDoubleLE: Buffer['readDoubleLE'];
  172. /**
  173. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  174. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  175. *
  176. * @param offset
  177. */
  178. readFloatBE: Buffer['readFloatBE'];
  179. /**
  180. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  181. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  182. *
  183. * @param offset
  184. */
  185. readFloatLE: Buffer['readFloatLE'];
  186. /**
  187. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  188. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  189. *
  190. * @param offset
  191. */
  192. readBigInt64BE: Buffer['readBigInt64BE'];
  193. /**
  194. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  195. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  196. *
  197. * @param offset
  198. */
  199. readBigInt64LE: Buffer['readBigInt64LE'];
  200. /**
  201. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  202. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  203. *
  204. * @param offset
  205. */
  206. readBigUInt64BE: Buffer['readBigUInt64BE'];
  207. /**
  208. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  209. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  210. *
  211. * @param offset
  212. */
  213. readBigUInt64LE: Buffer['readBigUInt64LE'];
  214. /**
  215. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  216. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  217. *
  218. * @param offset
  219. */
  220. readInt32BE: Buffer['readInt32BE'];
  221. /**
  222. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  223. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  224. *
  225. * @param offset
  226. */
  227. readInt32LE: Buffer['readInt32LE'];
  228. /**
  229. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  230. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  231. *
  232. * @param offset
  233. */
  234. readUInt32BE: Buffer['readUInt32BE'];
  235. /**
  236. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  237. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  238. *
  239. * @param offset
  240. */
  241. readUInt32LE: Buffer['readUInt32LE'];
  242. /**
  243. * All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
  244. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
  245. *
  246. * @param offset
  247. */
  248. readInt16BE: Buffer['readInt16BE'];
  249. /**
  250. * All of the standard byte-reading methods of the Buffer interface are
  251. * implemented and will operate across internal Buffer boundaries transparently.
  252. *
  253. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  254. * documentation for how these work.
  255. *
  256. * @param offset
  257. */
  258. readInt16LE: Buffer['readInt16LE'];
  259. /**
  260. * All of the standard byte-reading methods of the Buffer interface are
  261. * implemented and will operate across internal Buffer boundaries transparently.
  262. *
  263. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  264. * documentation for how these work.
  265. *
  266. * @param offset
  267. */
  268. readUInt16BE: Buffer['readUInt16BE'];
  269. /**
  270. * All of the standard byte-reading methods of the Buffer interface are
  271. * implemented and will operate across internal Buffer boundaries transparently.
  272. *
  273. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  274. * documentation for how these work.
  275. *
  276. * @param offset
  277. */
  278. readUInt16LE: Buffer['readUInt16LE'];
  279. /**
  280. * All of the standard byte-reading methods of the Buffer interface are
  281. * implemented and will operate across internal Buffer boundaries transparently.
  282. *
  283. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  284. * documentation for how these work.
  285. *
  286. * @param offset
  287. */
  288. readInt8: Buffer['readInt8'];
  289. /**
  290. * All of the standard byte-reading methods of the Buffer interface are
  291. * implemented and will operate across internal Buffer boundaries transparently.
  292. *
  293. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  294. * documentation for how these work.
  295. *
  296. * @param offset
  297. */
  298. readUInt8: Buffer['readUInt8'];
  299. /**
  300. * All of the standard byte-reading methods of the Buffer interface are
  301. * implemented and will operate across internal Buffer boundaries transparently.
  302. *
  303. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  304. * documentation for how these work.
  305. *
  306. * @param offset
  307. */
  308. readIntBE: Buffer['readIntBE'];
  309. /**
  310. * All of the standard byte-reading methods of the Buffer interface are
  311. * implemented and will operate across internal Buffer boundaries transparently.
  312. *
  313. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  314. * documentation for how these work.
  315. *
  316. * @param offset
  317. */
  318. readIntLE: Buffer['readIntLE'];
  319. /**
  320. * All of the standard byte-reading methods of the Buffer interface are
  321. * implemented and will operate across internal Buffer boundaries transparently.
  322. *
  323. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  324. * documentation for how these work.
  325. *
  326. * @param offset
  327. */
  328. readUIntBE: Buffer['readUIntBE'];
  329. /**
  330. * All of the standard byte-reading methods of the Buffer interface are
  331. * implemented and will operate across internal Buffer boundaries transparently.
  332. *
  333. * See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
  334. * documentation for how these work.
  335. *
  336. * @param offset
  337. */
  338. readUIntLE: Buffer['readUIntLE'];
  339. }
  340. /**
  341. * No arguments are required for the constructor, but you can initialise
  342. * the list by passing in a single Buffer object or an array of Buffer
  343. * objects.
  344. *
  345. * `new` is not strictly required, if you don't instantiate a new object,
  346. * it will be done automatically for you so you can create a new instance
  347. * simply with:
  348. *
  349. * ```js
  350. * const { BufferList } = require('bl')
  351. * const bl = BufferList()
  352. *
  353. * // equivalent to:
  354. *
  355. * const { BufferList } = require('bl')
  356. * const bl = new BufferList()
  357. * ```
  358. */
  359. declare const BufferList: BufferListConstructor;