plugin-data-source-mssql 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. package/README.md +31 -10
  2. package/dist/node_modules/tedious/245.index.js +741 -0
  3. package/dist/node_modules/tedious/LICENSE +21 -0
  4. package/dist/node_modules/tedious/appveyor.yml +67 -0
  5. package/dist/node_modules/tedious/benchmarks/bulk-load/iterable.js +61 -0
  6. package/dist/node_modules/tedious/benchmarks/common.js +287 -0
  7. package/dist/node_modules/tedious/benchmarks/connection/open.js +26 -0
  8. package/dist/node_modules/tedious/benchmarks/package-lock.json +21173 -0
  9. package/dist/node_modules/tedious/benchmarks/package.json +11 -0
  10. package/dist/node_modules/tedious/benchmarks/query/call-tvp.js +105 -0
  11. package/dist/node_modules/tedious/benchmarks/query/insert-varbinary.js +46 -0
  12. package/dist/node_modules/tedious/benchmarks/query/select-many-rows.js +63 -0
  13. package/dist/node_modules/tedious/benchmarks/query/select-nvarchar.js +50 -0
  14. package/dist/node_modules/tedious/benchmarks/query/select-varbinary.js +50 -0
  15. package/dist/node_modules/tedious/benchmarks/request/rpcrequest-payload-tvp.js +45 -0
  16. package/dist/node_modules/tedious/benchmarks/request/rpcrequest-payload-varbinary.js +37 -0
  17. package/dist/node_modules/tedious/benchmarks/token-parser/colmetadata-token.js +27 -0
  18. package/dist/node_modules/tedious/benchmarks/token-parser/done-token.js +28 -0
  19. package/dist/node_modules/tedious/benchmarks/token-parser/simple-tokens.js +363 -0
  20. package/dist/node_modules/tedious/lib/all-headers.d.ts +2 -0
  21. package/dist/node_modules/tedious/lib/all-headers.js +24 -0
  22. package/dist/node_modules/tedious/lib/always-encrypted/aead-aes-256-cbc-hmac-algorithm.js +82 -0
  23. package/dist/node_modules/tedious/lib/always-encrypted/aead-aes-256-cbc-hmac-encryption-key.js +55 -0
  24. package/dist/node_modules/tedious/lib/always-encrypted/cek-entry.d.ts +11 -0
  25. package/dist/node_modules/tedious/lib/always-encrypted/cek-entry.js +42 -0
  26. package/dist/node_modules/tedious/lib/always-encrypted/get-parameter-encryption-metadata.js +90 -0
  27. package/dist/node_modules/tedious/lib/always-encrypted/key-crypto.js +94 -0
  28. package/dist/node_modules/tedious/lib/always-encrypted/keystore-provider-azure-key-vault.d.ts +21 -0
  29. package/dist/node_modules/tedious/lib/always-encrypted/keystore-provider-azure-key-vault.js +247 -0
  30. package/dist/node_modules/tedious/lib/always-encrypted/symmetric-key-cache.js +36 -0
  31. package/dist/node_modules/tedious/lib/always-encrypted/symmetric-key.js +25 -0
  32. package/dist/node_modules/tedious/lib/always-encrypted/types.d.ts +73 -0
  33. package/dist/node_modules/tedious/lib/always-encrypted/types.js +48 -0
  34. package/dist/node_modules/tedious/lib/always-encrypted/utils.js +23 -0
  35. package/dist/node_modules/tedious/lib/bulk-load-payload.d.ts +8 -0
  36. package/dist/node_modules/tedious/lib/bulk-load-payload.js +23 -0
  37. package/dist/node_modules/tedious/lib/bulk-load.d.ts +275 -0
  38. package/dist/node_modules/tedious/lib/bulk-load.js +516 -0
  39. package/dist/node_modules/tedious/lib/collation.d.ts +28 -0
  40. package/dist/node_modules/tedious/lib/collation.js +348 -0
  41. package/dist/node_modules/tedious/lib/connection.d.ts +1310 -0
  42. package/dist/node_modules/tedious/lib/connection.js +2730 -0
  43. package/dist/node_modules/tedious/lib/connector.d.ts +18 -0
  44. package/dist/node_modules/tedious/lib/connector.js +150 -0
  45. package/dist/node_modules/tedious/lib/data-type.d.ts +455 -0
  46. package/dist/node_modules/tedious/lib/data-type.js +428 -0
  47. package/dist/node_modules/tedious/lib/data-types/bigint.d.ts +3 -0
  48. package/dist/node_modules/tedious/lib/data-types/bigint.js +53 -0
  49. package/dist/node_modules/tedious/lib/data-types/binary.d.ts +5 -0
  50. package/dist/node_modules/tedious/lib/data-types/binary.js +67 -0
  51. package/dist/node_modules/tedious/lib/data-types/bit.d.ts +3 -0
  52. package/dist/node_modules/tedious/lib/data-types/bit.js +46 -0
  53. package/dist/node_modules/tedious/lib/data-types/bitn.d.ts +3 -0
  54. package/dist/node_modules/tedious/lib/data-types/bitn.js +29 -0
  55. package/dist/node_modules/tedious/lib/data-types/char.d.ts +5 -0
  56. package/dist/node_modules/tedious/lib/data-types/char.js +86 -0
  57. package/dist/node_modules/tedious/lib/data-types/date.d.ts +3 -0
  58. package/dist/node_modules/tedious/lib/data-types/date.js +72 -0
  59. package/dist/node_modules/tedious/lib/data-types/datetime.d.ts +3 -0
  60. package/dist/node_modules/tedious/lib/data-types/datetime.js +93 -0
  61. package/dist/node_modules/tedious/lib/data-types/datetime2.d.ts +5 -0
  62. package/dist/node_modules/tedious/lib/data-types/datetime2.js +118 -0
  63. package/dist/node_modules/tedious/lib/data-types/datetimen.d.ts +3 -0
  64. package/dist/node_modules/tedious/lib/data-types/datetimen.js +29 -0
  65. package/dist/node_modules/tedious/lib/data-types/datetimeoffset.d.ts +5 -0
  66. package/dist/node_modules/tedious/lib/data-types/datetimeoffset.js +111 -0
  67. package/dist/node_modules/tedious/lib/data-types/decimal.d.ts +6 -0
  68. package/dist/node_modules/tedious/lib/data-types/decimal.js +107 -0
  69. package/dist/node_modules/tedious/lib/data-types/decimaln.d.ts +3 -0
  70. package/dist/node_modules/tedious/lib/data-types/decimaln.js +29 -0
  71. package/dist/node_modules/tedious/lib/data-types/float.d.ts +3 -0
  72. package/dist/node_modules/tedious/lib/data-types/float.js +47 -0
  73. package/dist/node_modules/tedious/lib/data-types/floatn.d.ts +3 -0
  74. package/dist/node_modules/tedious/lib/data-types/floatn.js +29 -0
  75. package/dist/node_modules/tedious/lib/data-types/image.d.ts +3 -0
  76. package/dist/node_modules/tedious/lib/data-types/image.js +56 -0
  77. package/dist/node_modules/tedious/lib/data-types/int.d.ts +3 -0
  78. package/dist/node_modules/tedious/lib/data-types/int.js +53 -0
  79. package/dist/node_modules/tedious/lib/data-types/intn.d.ts +3 -0
  80. package/dist/node_modules/tedious/lib/data-types/intn.js +29 -0
  81. package/dist/node_modules/tedious/lib/data-types/money.d.ts +3 -0
  82. package/dist/node_modules/tedious/lib/data-types/money.js +59 -0
  83. package/dist/node_modules/tedious/lib/data-types/moneyn.d.ts +3 -0
  84. package/dist/node_modules/tedious/lib/data-types/moneyn.js +29 -0
  85. package/dist/node_modules/tedious/lib/data-types/nchar.d.ts +5 -0
  86. package/dist/node_modules/tedious/lib/data-types/nchar.js +100 -0
  87. package/dist/node_modules/tedious/lib/data-types/ntext.d.ts +3 -0
  88. package/dist/node_modules/tedious/lib/data-types/ntext.js +60 -0
  89. package/dist/node_modules/tedious/lib/data-types/null.d.ts +3 -0
  90. package/dist/node_modules/tedious/lib/data-types/null.js +29 -0
  91. package/dist/node_modules/tedious/lib/data-types/numeric.d.ts +6 -0
  92. package/dist/node_modules/tedious/lib/data-types/numeric.js +106 -0
  93. package/dist/node_modules/tedious/lib/data-types/numericn.d.ts +3 -0
  94. package/dist/node_modules/tedious/lib/data-types/numericn.js +29 -0
  95. package/dist/node_modules/tedious/lib/data-types/nvarchar.d.ts +5 -0
  96. package/dist/node_modules/tedious/lib/data-types/nvarchar.js +133 -0
  97. package/dist/node_modules/tedious/lib/data-types/real.d.ts +3 -0
  98. package/dist/node_modules/tedious/lib/data-types/real.js +48 -0
  99. package/dist/node_modules/tedious/lib/data-types/smalldatetime.d.ts +3 -0
  100. package/dist/node_modules/tedious/lib/data-types/smalldatetime.js +83 -0
  101. package/dist/node_modules/tedious/lib/data-types/smallint.d.ts +3 -0
  102. package/dist/node_modules/tedious/lib/data-types/smallint.js +53 -0
  103. package/dist/node_modules/tedious/lib/data-types/smallmoney.d.ts +3 -0
  104. package/dist/node_modules/tedious/lib/data-types/smallmoney.js +51 -0
  105. package/dist/node_modules/tedious/lib/data-types/sql-variant.d.ts +3 -0
  106. package/dist/node_modules/tedious/lib/data-types/sql-variant.js +29 -0
  107. package/dist/node_modules/tedious/lib/data-types/text.d.ts +3 -0
  108. package/dist/node_modules/tedious/lib/data-types/text.js +69 -0
  109. package/dist/node_modules/tedious/lib/data-types/time.d.ts +3 -0
  110. package/dist/node_modules/tedious/lib/data-types/time.js +96 -0
  111. package/dist/node_modules/tedious/lib/data-types/tinyint.d.ts +3 -0
  112. package/dist/node_modules/tedious/lib/data-types/tinyint.js +53 -0
  113. package/dist/node_modules/tedious/lib/data-types/tvp.d.ts +3 -0
  114. package/dist/node_modules/tedious/lib/data-types/tvp.js +117 -0
  115. package/dist/node_modules/tedious/lib/data-types/udt.d.ts +3 -0
  116. package/dist/node_modules/tedious/lib/data-types/udt.js +29 -0
  117. package/dist/node_modules/tedious/lib/data-types/uniqueidentifier.d.ts +3 -0
  118. package/dist/node_modules/tedious/lib/data-types/uniqueidentifier.js +50 -0
  119. package/dist/node_modules/tedious/lib/data-types/varbinary.d.ts +5 -0
  120. package/dist/node_modules/tedious/lib/data-types/varbinary.js +119 -0
  121. package/dist/node_modules/tedious/lib/data-types/varchar.d.ts +5 -0
  122. package/dist/node_modules/tedious/lib/data-types/varchar.js +112 -0
  123. package/dist/node_modules/tedious/lib/data-types/xml.d.ts +3 -0
  124. package/dist/node_modules/tedious/lib/data-types/xml.js +29 -0
  125. package/dist/node_modules/tedious/lib/debug.d.ts +25 -0
  126. package/dist/node_modules/tedious/lib/debug.js +67 -0
  127. package/dist/node_modules/tedious/lib/errors/abort-error.d.ts +4 -0
  128. package/dist/node_modules/tedious/lib/errors/abort-error.js +15 -0
  129. package/dist/node_modules/tedious/lib/errors/timeout-error.d.ts +4 -0
  130. package/dist/node_modules/tedious/lib/errors/timeout-error.js +15 -0
  131. package/dist/node_modules/tedious/lib/errors.d.ts +17 -0
  132. package/dist/node_modules/tedious/lib/errors.js +23 -0
  133. package/dist/node_modules/tedious/lib/guid-parser.d.ts +3 -0
  134. package/dist/node_modules/tedious/lib/guid-parser.js +30 -0
  135. package/dist/node_modules/tedious/lib/incoming-message-stream.d.ts +19 -0
  136. package/dist/node_modules/tedious/lib/incoming-message-stream.js +97 -0
  137. package/dist/node_modules/tedious/lib/instance-lookup.d.ts +13 -0
  138. package/dist/node_modules/tedious/lib/instance-lookup.js +96 -0
  139. package/dist/node_modules/tedious/lib/library.d.ts +1 -0
  140. package/dist/node_modules/tedious/lib/library.js +8 -0
  141. package/dist/node_modules/tedious/lib/login7-payload.d.ts +51 -0
  142. package/dist/node_modules/tedious/lib/login7-payload.js +402 -0
  143. package/dist/node_modules/tedious/lib/message-io.d.ts +28 -0
  144. package/dist/node_modules/tedious/lib/message-io.js +153 -0
  145. package/dist/node_modules/tedious/lib/message.d.ts +11 -0
  146. package/dist/node_modules/tedious/lib/message.js +21 -0
  147. package/dist/node_modules/tedious/lib/metadata-parser.d.ts +48 -0
  148. package/dist/node_modules/tedious/lib/metadata-parser.js +380 -0
  149. package/dist/node_modules/tedious/lib/ntlm-payload.d.ts +23 -0
  150. package/dist/node_modules/tedious/lib/ntlm-payload.js +136 -0
  151. package/dist/node_modules/tedious/lib/ntlm.d.ts +4 -0
  152. package/dist/node_modules/tedious/lib/ntlm.js +72 -0
  153. package/dist/node_modules/tedious/lib/outgoing-message-stream.d.ts +15 -0
  154. package/dist/node_modules/tedious/lib/outgoing-message-stream.js +81 -0
  155. package/dist/node_modules/tedious/lib/packet.d.ts +33 -0
  156. package/dist/node_modules/tedious/lib/packet.js +191 -0
  157. package/dist/node_modules/tedious/lib/prelogin-payload.d.ts +61 -0
  158. package/dist/node_modules/tedious/lib/prelogin-payload.js +209 -0
  159. package/dist/node_modules/tedious/lib/request.d.ts +370 -0
  160. package/dist/node_modules/tedious/lib/request.js +387 -0
  161. package/dist/node_modules/tedious/lib/rpcrequest-payload.d.ts +16 -0
  162. package/dist/node_modules/tedious/lib/rpcrequest-payload.js +109 -0
  163. package/dist/node_modules/tedious/lib/sender.d.ts +5 -0
  164. package/dist/node_modules/tedious/lib/sender.js +83 -0
  165. package/dist/node_modules/tedious/lib/special-stored-procedure.d.ts +18 -0
  166. package/dist/node_modules/tedious/lib/special-stored-procedure.js +26 -0
  167. package/dist/node_modules/tedious/lib/sqlbatch-payload.d.ts +13 -0
  168. package/dist/node_modules/tedious/lib/sqlbatch-payload.js +34 -0
  169. package/dist/node_modules/tedious/lib/tds-versions.d.ts +6 -0
  170. package/dist/node_modules/tedious/lib/tds-versions.js +19 -0
  171. package/dist/node_modules/tedious/lib/tedious.d.ts +13 -0
  172. package/dist/node_modules/tedious/lib/tedious.js +249 -0
  173. package/dist/node_modules/tedious/lib/token/colmetadata-token-parser.d.ts +12 -0
  174. package/dist/node_modules/tedious/lib/token/colmetadata-token-parser.js +124 -0
  175. package/dist/node_modules/tedious/lib/token/done-token-parser.d.ts +6 -0
  176. package/dist/node_modules/tedious/lib/token/done-token-parser.js +76 -0
  177. package/dist/node_modules/tedious/lib/token/env-change-token-parser.d.ts +5 -0
  178. package/dist/node_modules/tedious/lib/token/env-change-token-parser.js +190 -0
  179. package/dist/node_modules/tedious/lib/token/feature-ext-ack-parser.d.ts +5 -0
  180. package/dist/node_modules/tedious/lib/token/feature-ext-ack-parser.js +52 -0
  181. package/dist/node_modules/tedious/lib/token/fedauth-info-parser.d.ts +5 -0
  182. package/dist/node_modules/tedious/lib/token/fedauth-info-parser.js +62 -0
  183. package/dist/node_modules/tedious/lib/token/handler.d.ts +135 -0
  184. package/dist/node_modules/tedious/lib/token/handler.js +444 -0
  185. package/dist/node_modules/tedious/lib/token/helpers.d.ts +28 -0
  186. package/dist/node_modules/tedious/lib/token/helpers.js +205 -0
  187. package/dist/node_modules/tedious/lib/token/infoerror-token-parser.d.ts +5 -0
  188. package/dist/node_modules/tedious/lib/token/infoerror-token-parser.js +80 -0
  189. package/dist/node_modules/tedious/lib/token/loginack-token-parser.d.ts +5 -0
  190. package/dist/node_modules/tedious/lib/token/loginack-token-parser.js +75 -0
  191. package/dist/node_modules/tedious/lib/token/nbcrow-token-parser.d.ts +4 -0
  192. package/dist/node_modules/tedious/lib/token/nbcrow-token-parser.js +104 -0
  193. package/dist/node_modules/tedious/lib/token/order-token-parser.d.ts +5 -0
  194. package/dist/node_modules/tedious/lib/token/order-token-parser.js +34 -0
  195. package/dist/node_modules/tedious/lib/token/returnstatus-token-parser.d.ts +5 -0
  196. package/dist/node_modules/tedious/lib/token/returnstatus-token-parser.js +21 -0
  197. package/dist/node_modules/tedious/lib/token/returnvalue-token-parser.d.ts +4 -0
  198. package/dist/node_modules/tedious/lib/token/returnvalue-token-parser.js +94 -0
  199. package/dist/node_modules/tedious/lib/token/row-token-parser.d.ts +4 -0
  200. package/dist/node_modules/tedious/lib/token/row-token-parser.js +77 -0
  201. package/dist/node_modules/tedious/lib/token/sspi-token-parser.d.ts +5 -0
  202. package/dist/node_modules/tedious/lib/token/sspi-token-parser.js +42 -0
  203. package/dist/node_modules/tedious/lib/token/stream-parser.d.ts +34 -0
  204. package/dist/node_modules/tedious/lib/token/stream-parser.js +341 -0
  205. package/dist/node_modules/tedious/lib/token/token-stream-parser.d.ts +15 -0
  206. package/dist/node_modules/tedious/lib/token/token-stream-parser.js +36 -0
  207. package/dist/node_modules/tedious/lib/token/token.d.ts +312 -0
  208. package/dist/node_modules/tedious/lib/token/token.js +328 -0
  209. package/dist/node_modules/tedious/lib/tracking-buffer/writable-tracking-buffer.d.ts +47 -0
  210. package/dist/node_modules/tedious/lib/tracking-buffer/writable-tracking-buffer.js +249 -0
  211. package/dist/node_modules/tedious/lib/transaction.d.ts +39 -0
  212. package/dist/node_modules/tedious/lib/transaction.js +137 -0
  213. package/dist/node_modules/tedious/lib/transient-error-lookup.d.ts +3 -0
  214. package/dist/node_modules/tedious/lib/transient-error-lookup.js +19 -0
  215. package/dist/node_modules/tedious/lib/utils/with-timeout.d.ts +7 -0
  216. package/dist/node_modules/tedious/lib/utils/with-timeout.js +36 -0
  217. package/dist/node_modules/tedious/lib/value-parser.d.ts +7 -0
  218. package/dist/node_modules/tedious/lib/value-parser.js +813 -0
  219. package/dist/node_modules/tedious/node_modules/@types/node/assert/strict.d.ts +105 -0
  220. package/dist/node_modules/tedious/node_modules/@types/node/assert.d.ts +955 -0
  221. package/dist/node_modules/tedious/node_modules/@types/node/async_hooks.d.ts +623 -0
  222. package/dist/node_modules/tedious/node_modules/@types/node/buffer.buffer.d.ts +466 -0
  223. package/dist/node_modules/tedious/node_modules/@types/node/buffer.d.ts +1810 -0
  224. package/dist/node_modules/tedious/node_modules/@types/node/child_process.d.ts +1428 -0
  225. package/dist/node_modules/tedious/node_modules/@types/node/cluster.d.ts +486 -0
  226. package/dist/node_modules/tedious/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  227. package/dist/node_modules/tedious/node_modules/@types/node/console.d.ts +151 -0
  228. package/dist/node_modules/tedious/node_modules/@types/node/constants.d.ts +20 -0
  229. package/dist/node_modules/tedious/node_modules/@types/node/crypto.d.ts +4065 -0
  230. package/dist/node_modules/tedious/node_modules/@types/node/dgram.d.ts +564 -0
  231. package/dist/node_modules/tedious/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
  232. package/dist/node_modules/tedious/node_modules/@types/node/dns/promises.d.ts +503 -0
  233. package/dist/node_modules/tedious/node_modules/@types/node/dns.d.ts +922 -0
  234. package/dist/node_modules/tedious/node_modules/@types/node/domain.d.ts +166 -0
  235. package/dist/node_modules/tedious/node_modules/@types/node/events.d.ts +1054 -0
  236. package/dist/node_modules/tedious/node_modules/@types/node/fs/promises.d.ts +1329 -0
  237. package/dist/node_modules/tedious/node_modules/@types/node/fs.d.ts +4676 -0
  238. package/dist/node_modules/tedious/node_modules/@types/node/globals.d.ts +150 -0
  239. package/dist/node_modules/tedious/node_modules/@types/node/globals.typedarray.d.ts +101 -0
  240. package/dist/node_modules/tedious/node_modules/@types/node/http.d.ts +2167 -0
  241. package/dist/node_modules/tedious/node_modules/@types/node/http2.d.ts +2480 -0
  242. package/dist/node_modules/tedious/node_modules/@types/node/https.d.ts +405 -0
  243. package/dist/node_modules/tedious/node_modules/@types/node/index.d.ts +115 -0
  244. package/dist/node_modules/tedious/node_modules/@types/node/inspector/promises.d.ts +41 -0
  245. package/dist/node_modules/tedious/node_modules/@types/node/inspector.d.ts +224 -0
  246. package/dist/node_modules/tedious/node_modules/@types/node/inspector.generated.d.ts +4226 -0
  247. package/dist/node_modules/tedious/node_modules/@types/node/module.d.ts +819 -0
  248. package/dist/node_modules/tedious/node_modules/@types/node/net.d.ts +933 -0
  249. package/dist/node_modules/tedious/node_modules/@types/node/os.d.ts +507 -0
  250. package/dist/node_modules/tedious/node_modules/@types/node/package.json +155 -0
  251. package/dist/node_modules/tedious/node_modules/@types/node/path/posix.d.ts +8 -0
  252. package/dist/node_modules/tedious/node_modules/@types/node/path/win32.d.ts +8 -0
  253. package/dist/node_modules/tedious/node_modules/@types/node/path.d.ts +187 -0
  254. package/dist/node_modules/tedious/node_modules/@types/node/perf_hooks.d.ts +643 -0
  255. package/dist/node_modules/tedious/node_modules/@types/node/process.d.ts +2161 -0
  256. package/dist/node_modules/tedious/node_modules/@types/node/punycode.d.ts +117 -0
  257. package/dist/node_modules/tedious/node_modules/@types/node/querystring.d.ts +152 -0
  258. package/dist/node_modules/tedious/node_modules/@types/node/quic.d.ts +910 -0
  259. package/dist/node_modules/tedious/node_modules/@types/node/readline/promises.d.ts +161 -0
  260. package/dist/node_modules/tedious/node_modules/@types/node/readline.d.ts +541 -0
  261. package/dist/node_modules/tedious/node_modules/@types/node/repl.d.ts +415 -0
  262. package/dist/node_modules/tedious/node_modules/@types/node/sea.d.ts +162 -0
  263. package/dist/node_modules/tedious/node_modules/@types/node/sqlite.d.ts +955 -0
  264. package/dist/node_modules/tedious/node_modules/@types/node/stream/consumers.d.ts +38 -0
  265. package/dist/node_modules/tedious/node_modules/@types/node/stream/promises.d.ts +211 -0
  266. package/dist/node_modules/tedious/node_modules/@types/node/stream/web.d.ts +296 -0
  267. package/dist/node_modules/tedious/node_modules/@types/node/stream.d.ts +1760 -0
  268. package/dist/node_modules/tedious/node_modules/@types/node/string_decoder.d.ts +67 -0
  269. package/dist/node_modules/tedious/node_modules/@types/node/test/reporters.d.ts +96 -0
  270. package/dist/node_modules/tedious/node_modules/@types/node/test.d.ts +2240 -0
  271. package/dist/node_modules/tedious/node_modules/@types/node/timers/promises.d.ts +108 -0
  272. package/dist/node_modules/tedious/node_modules/@types/node/timers.d.ts +159 -0
  273. package/dist/node_modules/tedious/node_modules/@types/node/tls.d.ts +1198 -0
  274. package/dist/node_modules/tedious/node_modules/@types/node/trace_events.d.ts +197 -0
  275. package/dist/node_modules/tedious/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +462 -0
  276. package/dist/node_modules/tedious/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  277. package/dist/node_modules/tedious/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
  278. package/dist/node_modules/tedious/node_modules/@types/node/ts5.6/index.d.ts +117 -0
  279. package/dist/node_modules/tedious/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  280. package/dist/node_modules/tedious/node_modules/@types/node/ts5.7/index.d.ts +117 -0
  281. package/dist/node_modules/tedious/node_modules/@types/node/tty.d.ts +250 -0
  282. package/dist/node_modules/tedious/node_modules/@types/node/url.d.ts +519 -0
  283. package/dist/node_modules/tedious/node_modules/@types/node/util/types.d.ts +558 -0
  284. package/dist/node_modules/tedious/node_modules/@types/node/util.d.ts +1662 -0
  285. package/dist/node_modules/tedious/node_modules/@types/node/v8.d.ts +983 -0
  286. package/dist/node_modules/tedious/node_modules/@types/node/vm.d.ts +1208 -0
  287. package/dist/node_modules/tedious/node_modules/@types/node/wasi.d.ts +202 -0
  288. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/abortcontroller.d.ts +59 -0
  289. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/blob.d.ts +23 -0
  290. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/console.d.ts +9 -0
  291. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
  292. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  293. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
  294. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/events.d.ts +106 -0
  295. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/fetch.d.ts +69 -0
  296. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
  297. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
  298. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  299. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/performance.d.ts +45 -0
  300. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  301. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/streams.d.ts +115 -0
  302. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/timers.d.ts +44 -0
  303. package/dist/node_modules/tedious/node_modules/@types/node/web-globals/url.d.ts +24 -0
  304. package/dist/node_modules/tedious/node_modules/@types/node/worker_threads.d.ts +717 -0
  305. package/dist/node_modules/tedious/node_modules/@types/node/zlib.d.ts +618 -0
  306. package/dist/node_modules/tedious/node_modules/bl/.github/dependabot.yml +16 -0
  307. package/dist/node_modules/tedious/node_modules/bl/.github/workflows/test-and-release.yml +61 -0
  308. package/dist/node_modules/tedious/node_modules/bl/BufferList.d.ts +431 -0
  309. package/dist/node_modules/tedious/node_modules/bl/BufferList.js +421 -0
  310. package/dist/node_modules/tedious/node_modules/bl/bl.js +84 -0
  311. package/dist/node_modules/tedious/node_modules/bl/index.d.ts +88 -0
  312. package/dist/node_modules/tedious/node_modules/bl/package.json +123 -0
  313. package/dist/node_modules/tedious/node_modules/bl/test/convert.js +21 -0
  314. package/dist/node_modules/tedious/node_modules/bl/test/indexOf.js +492 -0
  315. package/dist/node_modules/tedious/node_modules/bl/test/isBufferList.js +32 -0
  316. package/dist/node_modules/tedious/node_modules/bl/test/test.js +1032 -0
  317. package/dist/node_modules/tedious/node_modules/buffer/index.d.ts +194 -0
  318. package/dist/node_modules/tedious/node_modules/buffer/index.js +2106 -0
  319. package/dist/node_modules/tedious/node_modules/buffer/package.json +93 -0
  320. package/dist/node_modules/tedious/node_modules/readable-stream/lib/_stream_duplex.js +4 -0
  321. package/dist/node_modules/tedious/node_modules/readable-stream/lib/_stream_passthrough.js +4 -0
  322. package/dist/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js +4 -0
  323. package/dist/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js +4 -0
  324. package/dist/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js +4 -0
  325. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/add-abort-signal.js +52 -0
  326. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/buffer_list.js +157 -0
  327. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/compose.js +194 -0
  328. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/destroy.js +290 -0
  329. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/duplex.js +143 -0
  330. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/duplexify.js +378 -0
  331. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +286 -0
  332. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/from.js +98 -0
  333. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/lazy_transform.js +51 -0
  334. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/legacy.js +89 -0
  335. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/operators.js +457 -0
  336. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/passthrough.js +39 -0
  337. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/pipeline.js +471 -0
  338. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/readable.js +1290 -0
  339. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/state.js +39 -0
  340. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/transform.js +180 -0
  341. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/utils.js +327 -0
  342. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/streams/writable.js +819 -0
  343. package/dist/node_modules/tedious/node_modules/readable-stream/lib/internal/validators.js +530 -0
  344. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/browser.js +35 -0
  345. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/errors.js +343 -0
  346. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/index.js +65 -0
  347. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/primordials.js +124 -0
  348. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/util/inspect.js +55 -0
  349. package/dist/node_modules/tedious/node_modules/readable-stream/lib/ours/util.js +148 -0
  350. package/dist/node_modules/tedious/node_modules/readable-stream/lib/stream/promises.js +43 -0
  351. package/dist/node_modules/tedious/node_modules/readable-stream/lib/stream.js +143 -0
  352. package/dist/node_modules/tedious/node_modules/readable-stream/package.json +88 -0
  353. package/dist/node_modules/tedious/node_modules/sprintf-js/dist/.gitattributes +4 -0
  354. package/dist/node_modules/tedious/node_modules/sprintf-js/dist/angular-sprintf.min.js +3 -0
  355. package/dist/node_modules/tedious/node_modules/sprintf-js/dist/sprintf.min.js +3 -0
  356. package/dist/node_modules/tedious/node_modules/sprintf-js/package.json +35 -0
  357. package/dist/node_modules/tedious/node_modules/sprintf-js/src/angular-sprintf.js +24 -0
  358. package/dist/node_modules/tedious/node_modules/sprintf-js/src/sprintf.js +231 -0
  359. package/dist/node_modules/tedious/node_modules/undici-types/agent.d.ts +32 -0
  360. package/dist/node_modules/tedious/node_modules/undici-types/api.d.ts +43 -0
  361. package/dist/node_modules/tedious/node_modules/undici-types/balanced-pool.d.ts +29 -0
  362. package/dist/node_modules/tedious/node_modules/undici-types/cache-interceptor.d.ts +172 -0
  363. package/dist/node_modules/tedious/node_modules/undici-types/cache.d.ts +36 -0
  364. package/dist/node_modules/tedious/node_modules/undici-types/client-stats.d.ts +15 -0
  365. package/dist/node_modules/tedious/node_modules/undici-types/client.d.ts +108 -0
  366. package/dist/node_modules/tedious/node_modules/undici-types/connector.d.ts +34 -0
  367. package/dist/node_modules/tedious/node_modules/undici-types/content-type.d.ts +21 -0
  368. package/dist/node_modules/tedious/node_modules/undici-types/cookies.d.ts +30 -0
  369. package/dist/node_modules/tedious/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
  370. package/dist/node_modules/tedious/node_modules/undici-types/dispatcher.d.ts +276 -0
  371. package/dist/node_modules/tedious/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
  372. package/dist/node_modules/tedious/node_modules/undici-types/errors.d.ts +161 -0
  373. package/dist/node_modules/tedious/node_modules/undici-types/eventsource.d.ts +66 -0
  374. package/dist/node_modules/tedious/node_modules/undici-types/fetch.d.ts +211 -0
  375. package/dist/node_modules/tedious/node_modules/undici-types/formdata.d.ts +108 -0
  376. package/dist/node_modules/tedious/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  377. package/dist/node_modules/tedious/node_modules/undici-types/global-origin.d.ts +7 -0
  378. package/dist/node_modules/tedious/node_modules/undici-types/h2c-client.d.ts +73 -0
  379. package/dist/node_modules/tedious/node_modules/undici-types/handlers.d.ts +15 -0
  380. package/dist/node_modules/tedious/node_modules/undici-types/header.d.ts +160 -0
  381. package/dist/node_modules/tedious/node_modules/undici-types/index.d.ts +80 -0
  382. package/dist/node_modules/tedious/node_modules/undici-types/interceptors.d.ts +39 -0
  383. package/dist/node_modules/tedious/node_modules/undici-types/mock-agent.d.ts +68 -0
  384. package/dist/node_modules/tedious/node_modules/undici-types/mock-call-history.d.ts +111 -0
  385. package/dist/node_modules/tedious/node_modules/undici-types/mock-client.d.ts +27 -0
  386. package/dist/node_modules/tedious/node_modules/undici-types/mock-errors.d.ts +12 -0
  387. package/dist/node_modules/tedious/node_modules/undici-types/mock-interceptor.d.ts +94 -0
  388. package/dist/node_modules/tedious/node_modules/undici-types/mock-pool.d.ts +27 -0
  389. package/dist/node_modules/tedious/node_modules/undici-types/package.json +55 -0
  390. package/dist/node_modules/tedious/node_modules/undici-types/patch.d.ts +29 -0
  391. package/dist/node_modules/tedious/node_modules/undici-types/pool-stats.d.ts +19 -0
  392. package/dist/node_modules/tedious/node_modules/undici-types/pool.d.ts +41 -0
  393. package/dist/node_modules/tedious/node_modules/undici-types/proxy-agent.d.ts +29 -0
  394. package/dist/node_modules/tedious/node_modules/undici-types/readable.d.ts +68 -0
  395. package/dist/node_modules/tedious/node_modules/undici-types/retry-agent.d.ts +8 -0
  396. package/dist/node_modules/tedious/node_modules/undici-types/retry-handler.d.ts +125 -0
  397. package/dist/node_modules/tedious/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  398. package/dist/node_modules/tedious/node_modules/undici-types/util.d.ts +18 -0
  399. package/dist/node_modules/tedious/node_modules/undici-types/utility.d.ts +7 -0
  400. package/dist/node_modules/tedious/node_modules/undici-types/webidl.d.ts +341 -0
  401. package/dist/node_modules/tedious/node_modules/undici-types/websocket.d.ts +186 -0
  402. package/dist/node_modules/tedious/package.json +1 -0
  403. package/dist/node_modules/tedious/tsconfig.build-types.json +15 -0
  404. package/dist/node_modules/tedious/tsconfig.json +29 -0
  405. package/dist/node_modules/tedious/types/js-md4.d.ts +7 -0
  406. package/dist/node_modules/tedious/types/native-duplexpair.d.ts +12 -0
  407. package/dist/server/data-source/MssqlExternalDataSource.js +33 -2
  408. package/package.json +1 -1
@@ -0,0 +1,1032 @@
1
+ // @ts-check
2
+ 'use strict'
3
+
4
+ const tape = require('tape')
5
+ const crypto = require('crypto')
6
+ const fs = require('fs')
7
+ const path = require('path')
8
+ const os = require('os')
9
+ const BufferListStream = require('../')
10
+ const { Buffer } = require('buffer')
11
+
12
+ /**
13
+ * This typedef allows us to add _bufs to the API without declaring it publicly on types.
14
+ * @typedef { BufferListStream & { _bufs?: Buffer[] }} BufferListStreamWithPrivate
15
+ */
16
+
17
+ /**
18
+ * Just for typechecking in js
19
+ * @type { NodeJS.Process & { browser?: boolean }}
20
+ */
21
+
22
+ const process = globalThis.process
23
+
24
+ /** @type {BufferEncoding[]} */
25
+ const encodings = ['ascii', 'utf8', 'utf-8', 'hex', 'binary', 'base64']
26
+
27
+ if (process.browser) {
28
+ encodings.push(
29
+ 'ucs2',
30
+ 'ucs-2',
31
+ 'utf16le',
32
+ /**
33
+ * This alias is not in typescript typings for BufferEncoding. Still have to fix
34
+ * @see https://nodejs.org/api/buffer.html#buffers-and-character-encodings
35
+ */
36
+ // @ts-ignore
37
+ 'utf-16le'
38
+ )
39
+ }
40
+
41
+ require('./indexOf')
42
+ require('./isBufferList')
43
+ require('./convert')
44
+
45
+ tape('single bytes from single buffer', function (t) {
46
+ const bl = new BufferListStream()
47
+
48
+ bl.append(Buffer.from('abcd'))
49
+
50
+ t.equal(bl.length, 4)
51
+ t.equal(bl.get(-1), undefined)
52
+ t.equal(bl.get(0), 97)
53
+ t.equal(bl.get(1), 98)
54
+ t.equal(bl.get(2), 99)
55
+ t.equal(bl.get(3), 100)
56
+ t.equal(bl.get(4), undefined)
57
+
58
+ t.end()
59
+ })
60
+
61
+ tape('single bytes from multiple buffers', function (t) {
62
+ const bl = new BufferListStream()
63
+
64
+ bl.append(Buffer.from('abcd'))
65
+ bl.append(Buffer.from('efg'))
66
+ bl.append(Buffer.from('hi'))
67
+ bl.append(Buffer.from('j'))
68
+
69
+ t.equal(bl.length, 10)
70
+
71
+ t.equal(bl.get(0), 97)
72
+ t.equal(bl.get(1), 98)
73
+ t.equal(bl.get(2), 99)
74
+ t.equal(bl.get(3), 100)
75
+ t.equal(bl.get(4), 101)
76
+ t.equal(bl.get(5), 102)
77
+ t.equal(bl.get(6), 103)
78
+ t.equal(bl.get(7), 104)
79
+ t.equal(bl.get(8), 105)
80
+ t.equal(bl.get(9), 106)
81
+
82
+ t.end()
83
+ })
84
+
85
+ tape('multi bytes from single buffer', function (t) {
86
+ const bl = new BufferListStream()
87
+
88
+ bl.append(Buffer.from('abcd'))
89
+
90
+ t.equal(bl.length, 4)
91
+
92
+ t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
93
+ t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
94
+ t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
95
+ t.equal(bl.slice(-4, -1).toString('ascii'), 'abc')
96
+
97
+ t.end()
98
+ })
99
+
100
+ tape('multi bytes from single buffer (negative indexes)', function (t) {
101
+ const bl = new BufferListStream()
102
+
103
+ bl.append(Buffer.from('buffer'))
104
+
105
+ t.equal(bl.length, 6)
106
+
107
+ t.equal(bl.slice(-6, -1).toString('ascii'), 'buffe')
108
+ t.equal(bl.slice(-6, -2).toString('ascii'), 'buff')
109
+ t.equal(bl.slice(-5, -2).toString('ascii'), 'uff')
110
+
111
+ t.end()
112
+ })
113
+
114
+ tape('multiple bytes from multiple buffers', function (t) {
115
+ const bl = new BufferListStream()
116
+
117
+ bl.append(Buffer.from('abcd'))
118
+ bl.append(Buffer.from('efg'))
119
+ bl.append(Buffer.from('hi'))
120
+ bl.append(Buffer.from('j'))
121
+
122
+ t.equal(bl.length, 10)
123
+
124
+ t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
125
+ t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
126
+ t.equal(bl.slice(3, 6).toString('ascii'), 'def')
127
+ t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
128
+ t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
129
+ t.equal(bl.slice(-7, -4).toString('ascii'), 'def')
130
+
131
+ t.end()
132
+ })
133
+
134
+ tape('multiple bytes from multiple buffer lists', function (t) {
135
+ const bl = new BufferListStream()
136
+
137
+ bl.append(new BufferListStream([Buffer.from('abcd'), Buffer.from('efg')]))
138
+ bl.append(new BufferListStream([Buffer.from('hi'), Buffer.from('j')]))
139
+
140
+ t.equal(bl.length, 10)
141
+
142
+ t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
143
+
144
+ t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
145
+ t.equal(bl.slice(3, 6).toString('ascii'), 'def')
146
+ t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
147
+ t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
148
+
149
+ t.end()
150
+ })
151
+
152
+ // same data as previous test, just using nested constructors
153
+ tape('multiple bytes from crazy nested buffer lists', function (t) {
154
+ const bl = new BufferListStream()
155
+
156
+ bl.append(
157
+ new BufferListStream([
158
+ new BufferListStream([
159
+ new BufferListStream(Buffer.from('abc')),
160
+ Buffer.from('d'),
161
+ new BufferListStream(Buffer.from('efg'))
162
+ ]),
163
+ new BufferListStream([Buffer.from('hi')]),
164
+ new BufferListStream(Buffer.from('j'))
165
+ ])
166
+ )
167
+
168
+ t.equal(bl.length, 10)
169
+
170
+ t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
171
+
172
+ t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
173
+ t.equal(bl.slice(3, 6).toString('ascii'), 'def')
174
+ t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
175
+ t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
176
+
177
+ t.end()
178
+ })
179
+
180
+ tape('append accepts arrays of Buffers', function (t) {
181
+ const bl = new BufferListStream()
182
+
183
+ bl.append(Buffer.from('abc'))
184
+ bl.append([Buffer.from('def')])
185
+ bl.append([Buffer.from('ghi'), Buffer.from('jkl')])
186
+ bl.append([Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz')])
187
+ t.equal(bl.length, 26)
188
+ t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
189
+
190
+ t.end()
191
+ })
192
+
193
+ tape('append accepts arrays of Uint8Arrays', function (t) {
194
+ const bl = new BufferListStream()
195
+
196
+ bl.append(new Uint8Array([97, 98, 99]))
197
+ bl.append([Uint8Array.from([100, 101, 102])])
198
+ bl.append([new Uint8Array([103, 104, 105]), new Uint8Array([106, 107, 108])])
199
+ bl.append([new Uint8Array([109, 110, 111, 112]), new Uint8Array([113, 114, 115, 116, 117]), new Uint8Array([118, 119, 120, 121, 122])])
200
+ t.equal(bl.length, 26)
201
+ t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
202
+
203
+ t.end()
204
+ })
205
+
206
+ tape('append accepts arrays of BufferLists', function (t) {
207
+ const bl = new BufferListStream()
208
+
209
+ bl.append(Buffer.from('abc'))
210
+ bl.append([new BufferListStream('def')])
211
+ bl.append(
212
+ new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
213
+ )
214
+ bl.append([
215
+ Buffer.from('mnop'),
216
+ new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
217
+ ])
218
+ t.equal(bl.length, 26)
219
+ t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
220
+
221
+ t.end()
222
+ })
223
+
224
+ tape('append chainable', function (t) {
225
+ const bl = new BufferListStream()
226
+
227
+ t.ok(bl.append(Buffer.from('abcd')) === bl)
228
+ t.ok(bl.append([Buffer.from('abcd')]) === bl)
229
+ t.ok(bl.append(new BufferListStream(Buffer.from('abcd'))) === bl)
230
+ t.ok(bl.append([new BufferListStream(Buffer.from('abcd'))]) === bl)
231
+
232
+ t.end()
233
+ })
234
+
235
+ tape('append chainable (test results)', function (t) {
236
+ const bl = new BufferListStream('abc')
237
+ .append([new BufferListStream('def')])
238
+ .append(
239
+ new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
240
+ )
241
+ .append([
242
+ Buffer.from('mnop'),
243
+ new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
244
+ ])
245
+
246
+ t.equal(bl.length, 26)
247
+ t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
248
+
249
+ t.end()
250
+ })
251
+
252
+ tape('prepend accepts arrays of Buffers', function (t) {
253
+ const bl = new BufferListStream()
254
+
255
+ bl.prepend(Buffer.from('abc'))
256
+ bl.prepend([Buffer.from('def')])
257
+ bl.prepend([Buffer.from('ghi'), Buffer.from('jkl')])
258
+ bl.prepend([Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz')])
259
+ t.equal(bl.length, 26)
260
+ t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
261
+
262
+ t.end()
263
+ })
264
+
265
+ tape('prepend accepts arrays of Uint8Arrays', function (t) {
266
+ const bl = new BufferListStream()
267
+
268
+ bl.prepend(new Uint8Array([97, 98, 99]))
269
+ bl.prepend([Uint8Array.from([100, 101, 102])])
270
+ bl.prepend([new Uint8Array([103, 104, 105]), new Uint8Array([106, 107, 108])])
271
+ bl.prepend([new Uint8Array([109, 110, 111, 112]), new Uint8Array([113, 114, 115, 116, 117]), new Uint8Array([118, 119, 120, 121, 122])])
272
+ t.equal(bl.length, 26)
273
+ t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
274
+
275
+ t.end()
276
+ })
277
+
278
+ tape('prepend accepts arrays of BufferLists', function (t) {
279
+ const bl = new BufferListStream()
280
+
281
+ bl.prepend(Buffer.from('abc'))
282
+ bl.prepend([new BufferListStream('def')])
283
+ bl.prepend(
284
+ new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
285
+ )
286
+ bl.prepend([
287
+ Buffer.from('mnop'),
288
+ new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
289
+ ])
290
+ t.equal(bl.length, 26)
291
+ t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
292
+
293
+ t.end()
294
+ })
295
+
296
+ tape('prepend chainable', function (t) {
297
+ const bl = new BufferListStream()
298
+
299
+ t.ok(bl.prepend(Buffer.from('abcd')) === bl)
300
+ t.ok(bl.prepend([Buffer.from('abcd')]) === bl)
301
+ t.ok(bl.prepend(new BufferListStream(Buffer.from('abcd'))) === bl)
302
+ t.ok(bl.prepend([new BufferListStream(Buffer.from('abcd'))]) === bl)
303
+
304
+ t.end()
305
+ })
306
+
307
+ tape('prepend chainable (test results)', function (t) {
308
+ const bl = new BufferListStream('abc')
309
+ .prepend([new BufferListStream('def')])
310
+ .prepend(
311
+ new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
312
+ )
313
+ .prepend([
314
+ Buffer.from('mnop'),
315
+ new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
316
+ ])
317
+
318
+ t.equal(bl.length, 26)
319
+ t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
320
+
321
+ t.end()
322
+ })
323
+
324
+ tape('consuming from multiple buffers', function (t) {
325
+ const bl = new BufferListStream()
326
+
327
+ bl.append(Buffer.from('abcd'))
328
+ bl.append(Buffer.from('efg'))
329
+ bl.append(Buffer.from('hi'))
330
+ bl.append(Buffer.from('j'))
331
+
332
+ t.equal(bl.length, 10)
333
+
334
+ t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
335
+
336
+ bl.consume(3)
337
+ t.equal(bl.length, 7)
338
+ t.equal(bl.slice(0, 7).toString('ascii'), 'defghij')
339
+
340
+ bl.consume(2)
341
+ t.equal(bl.length, 5)
342
+ t.equal(bl.slice(0, 5).toString('ascii'), 'fghij')
343
+
344
+ bl.consume(1)
345
+ t.equal(bl.length, 4)
346
+ t.equal(bl.slice(0, 4).toString('ascii'), 'ghij')
347
+
348
+ bl.consume(1)
349
+ t.equal(bl.length, 3)
350
+ t.equal(bl.slice(0, 3).toString('ascii'), 'hij')
351
+
352
+ bl.consume(2)
353
+ t.equal(bl.length, 1)
354
+ t.equal(bl.slice(0, 1).toString('ascii'), 'j')
355
+
356
+ t.end()
357
+ })
358
+
359
+ tape('complete consumption', function (t) {
360
+ /** @type {BufferListStreamWithPrivate} */
361
+ const bl = new BufferListStream()
362
+
363
+ bl.append(Buffer.from('a'))
364
+ bl.append(Buffer.from('b'))
365
+
366
+ bl.consume(2)
367
+
368
+ t.equal(bl.length, 0)
369
+ t.equal(bl._bufs.length, 0)
370
+
371
+ t.end()
372
+ })
373
+
374
+ tape('test readUInt8 / readInt8', function (t) {
375
+ const buf1 = Buffer.alloc(1)
376
+ const buf2 = Buffer.alloc(3)
377
+ const buf3 = Buffer.alloc(3)
378
+ const bl = new BufferListStream()
379
+
380
+ buf1[0] = 0x1
381
+ buf2[1] = 0x3
382
+ buf2[2] = 0x4
383
+ buf3[0] = 0x23
384
+ buf3[1] = 0x42
385
+
386
+ bl.append(buf1)
387
+ bl.append(buf2)
388
+ bl.append(buf3)
389
+
390
+ t.equal(bl.readUInt8(), 0x1)
391
+ t.equal(bl.readUInt8(2), 0x3)
392
+ t.equal(bl.readInt8(2), 0x3)
393
+ t.equal(bl.readUInt8(3), 0x4)
394
+ t.equal(bl.readInt8(3), 0x4)
395
+ t.equal(bl.readUInt8(4), 0x23)
396
+ t.equal(bl.readInt8(4), 0x23)
397
+ t.equal(bl.readUInt8(5), 0x42)
398
+ t.equal(bl.readInt8(5), 0x42)
399
+
400
+ t.end()
401
+ })
402
+
403
+ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
404
+ const buf1 = Buffer.alloc(1)
405
+ const buf2 = Buffer.alloc(3)
406
+ const buf3 = Buffer.alloc(3)
407
+ const bl = new BufferListStream()
408
+
409
+ buf1[0] = 0x1
410
+ buf2[1] = 0x3
411
+ buf2[2] = 0x4
412
+ buf3[0] = 0x23
413
+ buf3[1] = 0x42
414
+
415
+ bl.append(buf1)
416
+ bl.append(buf2)
417
+ bl.append(buf3)
418
+
419
+ t.equal(bl.readUInt16BE(), 0x0100)
420
+ t.equal(bl.readUInt16LE(), 0x0001)
421
+ t.equal(bl.readUInt16BE(2), 0x0304)
422
+ t.equal(bl.readUInt16LE(2), 0x0403)
423
+ t.equal(bl.readInt16BE(2), 0x0304)
424
+ t.equal(bl.readInt16LE(2), 0x0403)
425
+ t.equal(bl.readUInt16BE(3), 0x0423)
426
+ t.equal(bl.readUInt16LE(3), 0x2304)
427
+ t.equal(bl.readInt16BE(3), 0x0423)
428
+ t.equal(bl.readInt16LE(3), 0x2304)
429
+ t.equal(bl.readUInt16BE(4), 0x2342)
430
+ t.equal(bl.readUInt16LE(4), 0x4223)
431
+ t.equal(bl.readInt16BE(4), 0x2342)
432
+ t.equal(bl.readInt16LE(4), 0x4223)
433
+
434
+ t.end()
435
+ })
436
+
437
+ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
438
+ const buf1 = Buffer.alloc(1)
439
+ const buf2 = Buffer.alloc(3)
440
+ const buf3 = Buffer.alloc(3)
441
+ const bl = new BufferListStream()
442
+
443
+ buf1[0] = 0x1
444
+ buf2[1] = 0x3
445
+ buf2[2] = 0x4
446
+ buf3[0] = 0x23
447
+ buf3[1] = 0x42
448
+
449
+ bl.append(buf1)
450
+ bl.append(buf2)
451
+ bl.append(buf3)
452
+
453
+ t.equal(bl.readUInt32BE(), 0x01000304)
454
+ t.equal(bl.readUInt32LE(), 0x04030001)
455
+ t.equal(bl.readUInt32BE(2), 0x03042342)
456
+ t.equal(bl.readUInt32LE(2), 0x42230403)
457
+ t.equal(bl.readInt32BE(2), 0x03042342)
458
+ t.equal(bl.readInt32LE(2), 0x42230403)
459
+
460
+ t.end()
461
+ })
462
+
463
+ tape('test readBigUInt64LE / readBigUInt64BE / readBigInt64LE / readBigInt64BE', function (t) {
464
+ const buf1 = Buffer.alloc(1)
465
+ const buf2 = Buffer.alloc(3)
466
+ const buf3 = Buffer.alloc(2)
467
+ const buf4 = Buffer.alloc(5)
468
+ const bl = new BufferListStream()
469
+
470
+ buf1[0] = 0x05
471
+ buf2[0] = 0x07
472
+
473
+ buf2[1] = 0x03
474
+ buf2[2] = 0x04
475
+ buf3[0] = 0x23
476
+ buf3[1] = 0x42
477
+ buf4[0] = 0x00
478
+ buf4[1] = 0x01
479
+ buf4[2] = 0x02
480
+ buf4[3] = 0x03
481
+
482
+ buf4[4] = 0x04
483
+
484
+ bl.append(buf1)
485
+ bl.append(buf2)
486
+ bl.append(buf3)
487
+ bl.append(buf4)
488
+
489
+ t.equal(bl.readBigUInt64BE(2), 0x0304234200010203n)
490
+ t.equal(bl.readBigUInt64LE(2), 0x0302010042230403n)
491
+ t.equal(bl.readBigInt64BE(2), 0x0304234200010203n)
492
+ t.equal(bl.readBigInt64LE(2), 0x0302010042230403n)
493
+
494
+ t.end()
495
+ })
496
+
497
+ tape('test readUIntLE / readUIntBE / readIntLE / readIntBE', function (t) {
498
+ const buf1 = Buffer.alloc(1)
499
+ const buf2 = Buffer.alloc(3)
500
+ const buf3 = Buffer.alloc(3)
501
+ const bl = new BufferListStream()
502
+
503
+ buf2[0] = 0x2
504
+ buf2[1] = 0x3
505
+ buf2[2] = 0x4
506
+ buf3[0] = 0x23
507
+ buf3[1] = 0x42
508
+ buf3[2] = 0x61
509
+
510
+ bl.append(buf1)
511
+ bl.append(buf2)
512
+ bl.append(buf3)
513
+
514
+ t.equal(bl.readUIntBE(1, 1), 0x02)
515
+ t.equal(bl.readUIntBE(1, 2), 0x0203)
516
+ t.equal(bl.readUIntBE(1, 3), 0x020304)
517
+ t.equal(bl.readUIntBE(1, 4), 0x02030423)
518
+ t.equal(bl.readUIntBE(1, 5), 0x0203042342)
519
+ t.equal(bl.readUIntBE(1, 6), 0x020304234261)
520
+ t.equal(bl.readUIntLE(1, 1), 0x02)
521
+ t.equal(bl.readUIntLE(1, 2), 0x0302)
522
+ t.equal(bl.readUIntLE(1, 3), 0x040302)
523
+ t.equal(bl.readUIntLE(1, 4), 0x23040302)
524
+ t.equal(bl.readUIntLE(1, 5), 0x4223040302)
525
+ t.equal(bl.readUIntLE(1, 6), 0x614223040302)
526
+ t.equal(bl.readIntBE(1, 1), 0x02)
527
+ t.equal(bl.readIntBE(1, 2), 0x0203)
528
+ t.equal(bl.readIntBE(1, 3), 0x020304)
529
+ t.equal(bl.readIntBE(1, 4), 0x02030423)
530
+ t.equal(bl.readIntBE(1, 5), 0x0203042342)
531
+ t.equal(bl.readIntBE(1, 6), 0x020304234261)
532
+ t.equal(bl.readIntLE(1, 1), 0x02)
533
+ t.equal(bl.readIntLE(1, 2), 0x0302)
534
+ t.equal(bl.readIntLE(1, 3), 0x040302)
535
+ t.equal(bl.readIntLE(1, 4), 0x23040302)
536
+ t.equal(bl.readIntLE(1, 5), 0x4223040302)
537
+ t.equal(bl.readIntLE(1, 6), 0x614223040302)
538
+
539
+ t.end()
540
+ })
541
+
542
+ tape('test readFloatLE / readFloatBE', function (t) {
543
+ const buf1 = Buffer.alloc(1)
544
+ const buf2 = Buffer.alloc(3)
545
+ const buf3 = Buffer.alloc(3)
546
+ const bl = new BufferListStream()
547
+
548
+ buf1[0] = 0x01
549
+ buf2[1] = 0x00
550
+ buf2[2] = 0x00
551
+ buf3[0] = 0x80
552
+ buf3[1] = 0x3f
553
+
554
+ bl.append(buf1)
555
+ bl.append(buf2)
556
+ bl.append(buf3)
557
+
558
+ const canonical = Buffer.concat([buf1, buf2, buf3])
559
+ t.equal(bl.readFloatLE(), canonical.readFloatLE())
560
+ t.equal(bl.readFloatBE(), canonical.readFloatBE())
561
+ t.equal(bl.readFloatLE(2), canonical.readFloatLE(2))
562
+ t.equal(bl.readFloatBE(2), canonical.readFloatBE(2))
563
+
564
+ t.end()
565
+ })
566
+
567
+ tape('test readDoubleLE / readDoubleBE', function (t) {
568
+ const buf1 = Buffer.alloc(1)
569
+ const buf2 = Buffer.alloc(3)
570
+ const buf3 = Buffer.alloc(10)
571
+ const bl = new BufferListStream()
572
+
573
+ buf1[0] = 0x01
574
+ buf2[1] = 0x55
575
+ buf2[2] = 0x55
576
+ buf3[0] = 0x55
577
+ buf3[1] = 0x55
578
+ buf3[2] = 0x55
579
+ buf3[3] = 0x55
580
+ buf3[4] = 0xd5
581
+ buf3[5] = 0x3f
582
+
583
+ bl.append(buf1)
584
+ bl.append(buf2)
585
+ bl.append(buf3)
586
+
587
+ const canonical = Buffer.concat([buf1, buf2, buf3])
588
+ t.equal(bl.readDoubleBE(), canonical.readDoubleBE())
589
+ t.equal(bl.readDoubleLE(), canonical.readDoubleLE())
590
+ t.equal(bl.readDoubleBE(2), canonical.readDoubleBE(2))
591
+ t.equal(bl.readDoubleLE(2), canonical.readDoubleLE(2))
592
+
593
+ t.end()
594
+ })
595
+
596
+ tape('test toString', function (t) {
597
+ const bl = new BufferListStream()
598
+
599
+ bl.append(Buffer.from('abcd'))
600
+ bl.append(Buffer.from('efg'))
601
+ bl.append(Buffer.from('hi'))
602
+ bl.append(Buffer.from('j'))
603
+
604
+ t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
605
+ t.equal(bl.toString('ascii', 3, 10), 'defghij')
606
+ t.equal(bl.toString('ascii', 3, 6), 'def')
607
+ t.equal(bl.toString('ascii', 3, 8), 'defgh')
608
+ t.equal(bl.toString('ascii', 5, 10), 'fghij')
609
+
610
+ t.end()
611
+ })
612
+
613
+ tape('test toString encoding', function (t) {
614
+ const bl = new BufferListStream()
615
+ const b = Buffer.from('abcdefghij\xff\x00')
616
+
617
+ bl.append(Buffer.from('abcd'))
618
+ bl.append(Buffer.from('efg'))
619
+ bl.append(Buffer.from('hi'))
620
+ bl.append(Buffer.from('j'))
621
+ bl.append(Buffer.from('\xff\x00'))
622
+
623
+ encodings.forEach(function (enc) {
624
+ t.equal(bl.toString(enc), b.toString(enc), enc)
625
+ })
626
+
627
+ t.end()
628
+ })
629
+
630
+ tape('getBuffers', function (t) {
631
+ const bl = new BufferListStream([Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')])
632
+
633
+ t.deepEquals(
634
+ bl.getBuffers(),
635
+ // @ts-ignore
636
+ bl._bufs
637
+ )
638
+
639
+ t.end()
640
+ })
641
+
642
+ tape('uninitialized memory', function (t) {
643
+ const secret = crypto.randomBytes(256)
644
+ for (let i = 0; i < 1e6; i++) {
645
+ const clone = Buffer.from(secret)
646
+ const bl = new BufferListStream()
647
+ bl.append(Buffer.from('a'))
648
+ bl.consume(-1024)
649
+ const buf = bl.slice(1)
650
+ if (buf.indexOf(clone) !== -1) {
651
+ t.fail(`Match (at ${i})`)
652
+ break
653
+ }
654
+ }
655
+ t.end()
656
+ })
657
+
658
+ !process.browser && tape('test stream', function (t) {
659
+ const random = crypto.randomBytes(65534)
660
+
661
+ const bl = new BufferListStream((err, buf) => {
662
+ t.ok(Buffer.isBuffer(buf))
663
+ t.ok(err === null)
664
+ t.ok(random.equals(bl.slice()))
665
+ t.ok(random.equals(buf.slice()))
666
+
667
+ bl.pipe(fs.createWriteStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat')))
668
+ .on('close', function () {
669
+ const rndhash = crypto.createHash('md5').update(random).digest('hex')
670
+ const md5sum = crypto.createHash('md5')
671
+ const s = fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat'))
672
+
673
+ s.on('data', md5sum.update.bind(md5sum))
674
+ s.on('end', function () {
675
+ t.equal(rndhash, md5sum.digest('hex'), 'woohoo! correct hash!')
676
+ t.end()
677
+ })
678
+ })
679
+ })
680
+
681
+ fs.writeFileSync(path.join(os.tmpdir(), 'bl_test_rnd.dat'), random)
682
+ fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd.dat')).pipe(bl)
683
+ })
684
+
685
+ tape('instantiation with Buffer', function (t) {
686
+ const buf = crypto.randomBytes(1024)
687
+ const buf2 = crypto.randomBytes(1024)
688
+ let b = BufferListStream(buf)
689
+
690
+ t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
691
+ b = BufferListStream([buf, buf2])
692
+ t.equal(b.slice().toString('hex'), Buffer.concat([buf, buf2]).toString('hex'), 'same buffer')
693
+
694
+ t.end()
695
+ })
696
+
697
+ tape('test String appendage', function (t) {
698
+ const bl = new BufferListStream()
699
+ const b = Buffer.from('abcdefghij\xff\x00')
700
+
701
+ bl.append('abcd')
702
+ bl.append('efg')
703
+ bl.append('hi')
704
+ bl.append('j')
705
+ bl.append('\xff\x00')
706
+
707
+ encodings.forEach(function (enc) {
708
+ t.equal(bl.toString(enc), b.toString(enc))
709
+ })
710
+
711
+ t.end()
712
+ })
713
+
714
+ tape('test Number appendage', function (t) {
715
+ const bl = new BufferListStream()
716
+ const b = Buffer.from('1234567890')
717
+
718
+ bl.append(1234)
719
+ bl.append(567)
720
+ bl.append(89)
721
+ bl.append(0)
722
+
723
+ encodings.forEach(function (enc) {
724
+ t.equal(bl.toString(enc), b.toString(enc))
725
+ })
726
+
727
+ t.end()
728
+ })
729
+
730
+ tape('write nothing, should get empty buffer', function (t) {
731
+ t.plan(3)
732
+ BufferListStream(function (err, data) {
733
+ t.notOk(err, 'no error')
734
+ t.ok(Buffer.isBuffer(data), 'got a buffer')
735
+ t.equal(0, data.length, 'got a zero-length buffer')
736
+ t.end()
737
+ }).end()
738
+ })
739
+
740
+ tape('unicode string', function (t) {
741
+ t.plan(2)
742
+
743
+ const inp1 = '\u2600'
744
+ const inp2 = '\u2603'
745
+ const exp = inp1 + ' and ' + inp2
746
+ const bl = BufferListStream()
747
+
748
+ bl.write(inp1)
749
+ bl.write(' and ')
750
+ bl.write(inp2)
751
+ t.equal(exp, bl.toString())
752
+ t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
753
+ })
754
+
755
+ tape('should emit finish', function (t) {
756
+ const source = BufferListStream()
757
+ const dest = BufferListStream()
758
+
759
+ source.write('hello')
760
+ source.pipe(dest)
761
+
762
+ dest.on('finish', function () {
763
+ t.equal(dest.toString('utf8'), 'hello')
764
+ t.end()
765
+ })
766
+ })
767
+
768
+ tape('basic copy', function (t) {
769
+ const buf = crypto.randomBytes(1024)
770
+ const buf2 = Buffer.alloc(1024)
771
+ const b = BufferListStream(buf)
772
+
773
+ b.copy(buf2)
774
+ t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
775
+
776
+ t.end()
777
+ })
778
+
779
+ tape('copy after many appends', function (t) {
780
+ const buf = crypto.randomBytes(512)
781
+ const buf2 = Buffer.alloc(1024)
782
+ const b = BufferListStream(buf)
783
+
784
+ b.append(buf)
785
+ b.copy(buf2)
786
+ t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
787
+
788
+ t.end()
789
+ })
790
+
791
+ tape('copy at a precise position', function (t) {
792
+ const buf = crypto.randomBytes(1004)
793
+ const buf2 = Buffer.alloc(1024)
794
+ const b = BufferListStream(buf)
795
+
796
+ b.copy(buf2, 20)
797
+ t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
798
+
799
+ t.end()
800
+ })
801
+
802
+ tape('copy starting from a precise location', function (t) {
803
+ const buf = crypto.randomBytes(10)
804
+ const buf2 = Buffer.alloc(5)
805
+ const b = BufferListStream(buf)
806
+
807
+ b.copy(buf2, 0, 5)
808
+ t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
809
+
810
+ t.end()
811
+ })
812
+
813
+ tape('copy in an interval', function (t) {
814
+ const rnd = crypto.randomBytes(10)
815
+ const b = BufferListStream(rnd) // put the random bytes there
816
+ const actual = Buffer.alloc(3)
817
+ const expected = Buffer.alloc(3)
818
+
819
+ rnd.copy(expected, 0, 5, 8)
820
+ b.copy(actual, 0, 5, 8)
821
+
822
+ t.equal(actual.toString('hex'), expected.toString('hex'), 'same buffer')
823
+
824
+ t.end()
825
+ })
826
+
827
+ tape('copy an interval between two buffers', function (t) {
828
+ const buf = crypto.randomBytes(10)
829
+ const buf2 = Buffer.alloc(10)
830
+ const b = BufferListStream(buf)
831
+
832
+ b.append(buf)
833
+ b.copy(buf2, 0, 5, 15)
834
+
835
+ t.equal(b.slice(5, 15).toString('hex'), buf2.toString('hex'), 'same buffer')
836
+
837
+ t.end()
838
+ })
839
+
840
+ tape('shallow slice across buffer boundaries', function (t) {
841
+ const bl = new BufferListStream(['First', 'Second', 'Third'])
842
+
843
+ t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')
844
+
845
+ t.end()
846
+ })
847
+
848
+ tape('shallow slice within single buffer', function (t) {
849
+ t.plan(2)
850
+
851
+ const bl = new BufferListStream(['First', 'Second', 'Third'])
852
+
853
+ t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
854
+ t.equal(bl.shallowSlice(7, 10).toString(), 'con')
855
+
856
+ t.end()
857
+ })
858
+
859
+ tape('shallow slice single buffer', function (t) {
860
+ t.plan(3)
861
+
862
+ const bl = new BufferListStream(['First', 'Second', 'Third'])
863
+
864
+ t.equal(bl.shallowSlice(0, 5).toString(), 'First')
865
+ t.equal(bl.shallowSlice(5, 11).toString(), 'Second')
866
+ t.equal(bl.shallowSlice(11, 16).toString(), 'Third')
867
+ })
868
+
869
+ tape('shallow slice with negative or omitted indices', function (t) {
870
+ t.plan(4)
871
+
872
+ const bl = new BufferListStream(['First', 'Second', 'Third'])
873
+
874
+ t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')
875
+ t.equal(bl.shallowSlice(5).toString(), 'SecondThird')
876
+ t.equal(bl.shallowSlice(5, -3).toString(), 'SecondTh')
877
+ t.equal(bl.shallowSlice(-8).toString(), 'ondThird')
878
+ })
879
+
880
+ tape('shallow slice does not make a copy', function (t) {
881
+ t.plan(1)
882
+
883
+ const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
884
+ const bl = new BufferListStream(buffers).shallowSlice(5, -3)
885
+
886
+ buffers[1].fill('h')
887
+ buffers[2].fill('h')
888
+
889
+ t.equal(bl.toString(), 'hhhhhhhh')
890
+ })
891
+
892
+ tape('shallow slice with 0 length', function (t) {
893
+ t.plan(1)
894
+
895
+ const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
896
+ const bl = (new BufferListStream(buffers)).shallowSlice(0, 0)
897
+
898
+ t.equal(bl.length, 0)
899
+ })
900
+
901
+ tape('shallow slice with 0 length from middle', function (t) {
902
+ t.plan(1)
903
+
904
+ const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
905
+ const bl = (new BufferListStream(buffers)).shallowSlice(10, 10)
906
+
907
+ t.equal(bl.length, 0)
908
+ })
909
+
910
+ tape('duplicate', function (t) {
911
+ t.plan(2)
912
+
913
+ const bl = new BufferListStream('abcdefghij\xff\x00')
914
+ const dup = bl.duplicate()
915
+
916
+ t.equal(bl.prototype, dup.prototype)
917
+ t.equal(bl.toString('hex'), dup.toString('hex'))
918
+ })
919
+
920
+ tape('destroy no pipe', function (t) {
921
+ t.plan(2)
922
+
923
+ /** @type {BufferListStreamWithPrivate} */
924
+ const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')
925
+
926
+ bl.destroy()
927
+
928
+ t.equal(bl._bufs.length, 0)
929
+ t.equal(bl.length, 0)
930
+ })
931
+
932
+ tape('destroy with error', function (t) {
933
+ t.plan(3)
934
+
935
+ /** @type {BufferListStreamWithPrivate} */
936
+ const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')
937
+ const err = new Error('kaboom')
938
+
939
+ bl.destroy(err)
940
+ bl.on('error', function (_err) {
941
+ t.equal(_err, err)
942
+ })
943
+
944
+ t.equal(bl._bufs.length, 0)
945
+ t.equal(bl.length, 0)
946
+ })
947
+
948
+ !process.browser && tape('destroy with pipe before read end', function (t) {
949
+ t.plan(2)
950
+
951
+ /** @type {BufferListStreamWithPrivate} */
952
+ const bl = new BufferListStream()
953
+ fs.createReadStream(path.join(__dirname, '/test.js'))
954
+ .pipe(bl)
955
+
956
+ bl.destroy()
957
+
958
+ t.equal(bl._bufs.length, 0)
959
+ t.equal(bl.length, 0)
960
+ })
961
+
962
+ !process.browser && tape('destroy with pipe before read end with race', function (t) {
963
+ t.plan(2)
964
+
965
+ /** @type {BufferListStreamWithPrivate} */
966
+ const bl = new BufferListStream()
967
+
968
+ fs.createReadStream(path.join(__dirname, '/test.js'))
969
+ .pipe(bl)
970
+
971
+ setTimeout(function () {
972
+ bl.destroy()
973
+ setTimeout(function () {
974
+ t.equal(bl._bufs.length, 0)
975
+ t.equal(bl.length, 0)
976
+ }, 500)
977
+ }, 500)
978
+ })
979
+
980
+ !process.browser && tape('destroy with pipe after read end', function (t) {
981
+ t.plan(2)
982
+
983
+ /** @type {BufferListStreamWithPrivate} */
984
+ const bl = new BufferListStream()
985
+ fs.createReadStream(path.join(__dirname, '/test.js'))
986
+ .on('end', onEnd)
987
+ .pipe(bl)
988
+
989
+ function onEnd () {
990
+ bl.destroy()
991
+
992
+ t.equal(bl._bufs.length, 0)
993
+ t.equal(bl.length, 0)
994
+ }
995
+ })
996
+
997
+ !process.browser && tape('destroy with pipe while writing to a destination', function (t) {
998
+ t.plan(4)
999
+
1000
+ /** @type {BufferListStreamWithPrivate} */
1001
+ const bl = new BufferListStream()
1002
+ const ds = new BufferListStream()
1003
+
1004
+ fs.createReadStream(path.join(__dirname, '/test.js'))
1005
+ .on('end', onEnd)
1006
+ .pipe(bl)
1007
+
1008
+ function onEnd () {
1009
+ bl.pipe(ds)
1010
+
1011
+ setTimeout(function () {
1012
+ bl.destroy()
1013
+
1014
+ t.equals(bl._bufs.length, 0)
1015
+ t.equals(bl.length, 0)
1016
+
1017
+ ds.destroy()
1018
+
1019
+ t.equals(bl._bufs.length, 0)
1020
+ t.equals(bl.length, 0)
1021
+ }, 100)
1022
+ }
1023
+ })
1024
+
1025
+ !process.browser && tape('handle error', function (t) {
1026
+ t.plan(2)
1027
+
1028
+ fs.createReadStream('/does/not/exist').pipe(BufferListStream(function (err, data) {
1029
+ t.ok(err instanceof Error, 'has error')
1030
+ t.notOk(data, 'no data')
1031
+ }))
1032
+ })