@owlmeans/file-streams 0.0.0-stage → 0.2.0-alpha.0

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 (475) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/agent-meta/manifest.json +64 -0
  4. package/agent-meta/skills/file-streams/SKILL.md +183 -0
  5. package/agent-meta/skills/file-streams/parts/network.md +47 -0
  6. package/agent-meta/skills/file-streams/parts/workspaces.md +129 -0
  7. package/build/archive/consts.d.ts +16 -0
  8. package/build/archive/consts.d.ts.map +1 -0
  9. package/build/archive/consts.js +24 -0
  10. package/build/archive/consts.js.map +1 -0
  11. package/build/archive/formats.d.ts +4 -0
  12. package/build/archive/formats.d.ts.map +1 -0
  13. package/build/archive/formats.js +53 -0
  14. package/build/archive/formats.js.map +1 -0
  15. package/build/archive/guard.d.ts +5 -0
  16. package/build/archive/guard.d.ts.map +1 -0
  17. package/build/archive/guard.js +62 -0
  18. package/build/archive/guard.js.map +1 -0
  19. package/build/archive/ratio.d.ts +5 -0
  20. package/build/archive/ratio.d.ts.map +1 -0
  21. package/build/archive/ratio.js +30 -0
  22. package/build/archive/ratio.js.map +1 -0
  23. package/build/archive/tar.d.ts +4 -0
  24. package/build/archive/tar.d.ts.map +1 -0
  25. package/build/archive/tar.js +142 -0
  26. package/build/archive/tar.js.map +1 -0
  27. package/build/archive/types.d.ts +95 -0
  28. package/build/archive/types.d.ts.map +1 -0
  29. package/build/archive/types.js +2 -0
  30. package/build/archive/types.js.map +1 -0
  31. package/build/archive/types.local.d.ts +64 -0
  32. package/build/archive/types.local.d.ts.map +1 -0
  33. package/build/archive/types.local.js +2 -0
  34. package/build/archive/types.local.js.map +1 -0
  35. package/build/archive/zip.d.ts +4 -0
  36. package/build/archive/zip.d.ts.map +1 -0
  37. package/build/archive/zip.js +135 -0
  38. package/build/archive/zip.js.map +1 -0
  39. package/build/archive.d.ts +4 -0
  40. package/build/archive.d.ts.map +1 -0
  41. package/build/archive.js +265 -0
  42. package/build/archive.js.map +1 -0
  43. package/build/backed-workspace/types.d.ts +67 -0
  44. package/build/backed-workspace/types.d.ts.map +1 -0
  45. package/build/backed-workspace/types.js +2 -0
  46. package/build/backed-workspace/types.js.map +1 -0
  47. package/build/backed-workspace.d.ts +4 -0
  48. package/build/backed-workspace.d.ts.map +1 -0
  49. package/build/backed-workspace.js +63 -0
  50. package/build/backed-workspace.js.map +1 -0
  51. package/build/consts.d.ts +3 -0
  52. package/build/consts.d.ts.map +1 -0
  53. package/build/consts.js +3 -0
  54. package/build/consts.js.map +1 -0
  55. package/build/consts.local.d.ts +3 -0
  56. package/build/consts.local.d.ts.map +1 -0
  57. package/build/consts.local.js +3 -0
  58. package/build/consts.local.js.map +1 -0
  59. package/build/errors.d.ts +59 -0
  60. package/build/errors.d.ts.map +1 -0
  61. package/build/errors.js +105 -0
  62. package/build/errors.js.map +1 -0
  63. package/build/http/connector.d.ts +11 -0
  64. package/build/http/connector.d.ts.map +1 -0
  65. package/build/http/connector.js +124 -0
  66. package/build/http/connector.js.map +1 -0
  67. package/build/http/consts.d.ts +9 -0
  68. package/build/http/consts.d.ts.map +1 -0
  69. package/build/http/consts.js +8 -0
  70. package/build/http/consts.js.map +1 -0
  71. package/build/http/source.d.ts +5 -0
  72. package/build/http/source.d.ts.map +1 -0
  73. package/build/http/source.js +76 -0
  74. package/build/http/source.js.map +1 -0
  75. package/build/http/types.d.ts +67 -0
  76. package/build/http/types.d.ts.map +1 -0
  77. package/build/http/types.js +2 -0
  78. package/build/http/types.js.map +1 -0
  79. package/build/http/types.local.d.ts +21 -0
  80. package/build/http/types.local.d.ts.map +1 -0
  81. package/build/http/types.local.js +2 -0
  82. package/build/http/types.local.js.map +1 -0
  83. package/build/http.d.ts +4 -0
  84. package/build/http.d.ts.map +1 -0
  85. package/build/http.js +248 -0
  86. package/build/http.js.map +1 -0
  87. package/build/index.d.ts +53 -0
  88. package/build/index.d.ts.map +1 -0
  89. package/build/index.js +33 -0
  90. package/build/index.js.map +1 -0
  91. package/build/network/consts.d.ts +12 -0
  92. package/build/network/consts.d.ts.map +1 -0
  93. package/build/network/consts.js +20 -0
  94. package/build/network/consts.js.map +1 -0
  95. package/build/network/types.d.ts +43 -0
  96. package/build/network/types.d.ts.map +1 -0
  97. package/build/network/types.js +2 -0
  98. package/build/network/types.js.map +1 -0
  99. package/build/network.d.ts +4 -0
  100. package/build/network.d.ts.map +1 -0
  101. package/build/network.js +165 -0
  102. package/build/network.js.map +1 -0
  103. package/build/proxy/consts.d.ts +7 -0
  104. package/build/proxy/consts.d.ts.map +1 -0
  105. package/build/proxy/consts.js +9 -0
  106. package/build/proxy/consts.js.map +1 -0
  107. package/build/proxy/endpoint.d.ts +4 -0
  108. package/build/proxy/endpoint.d.ts.map +1 -0
  109. package/build/proxy/endpoint.js +27 -0
  110. package/build/proxy/endpoint.js.map +1 -0
  111. package/build/proxy/http.d.ts +5 -0
  112. package/build/proxy/http.d.ts.map +1 -0
  113. package/build/proxy/http.js +95 -0
  114. package/build/proxy/http.js.map +1 -0
  115. package/build/proxy/router.d.ts +4 -0
  116. package/build/proxy/router.d.ts.map +1 -0
  117. package/build/proxy/router.js +85 -0
  118. package/build/proxy/router.js.map +1 -0
  119. package/build/proxy/socks.d.ts +5 -0
  120. package/build/proxy/socks.d.ts.map +1 -0
  121. package/build/proxy/socks.js +44 -0
  122. package/build/proxy/socks.js.map +1 -0
  123. package/build/proxy/types.d.ts +99 -0
  124. package/build/proxy/types.d.ts.map +1 -0
  125. package/build/proxy/types.js +2 -0
  126. package/build/proxy/types.js.map +1 -0
  127. package/build/resolvers/google-drive/consts.d.ts +10 -0
  128. package/build/resolvers/google-drive/consts.d.ts.map +1 -0
  129. package/build/resolvers/google-drive/consts.js +16 -0
  130. package/build/resolvers/google-drive/consts.js.map +1 -0
  131. package/build/resolvers/google-drive/types.d.ts +21 -0
  132. package/build/resolvers/google-drive/types.d.ts.map +1 -0
  133. package/build/resolvers/google-drive/types.js +2 -0
  134. package/build/resolvers/google-drive/types.js.map +1 -0
  135. package/build/resolvers/google-drive.d.ts +10 -0
  136. package/build/resolvers/google-drive.d.ts.map +1 -0
  137. package/build/resolvers/google-drive.js +130 -0
  138. package/build/resolvers/google-drive.js.map +1 -0
  139. package/build/resolvers/types.d.ts +39 -0
  140. package/build/resolvers/types.d.ts.map +1 -0
  141. package/build/resolvers/types.js +2 -0
  142. package/build/resolvers/types.js.map +1 -0
  143. package/build/s3/consts.d.ts +9 -0
  144. package/build/s3/consts.d.ts.map +1 -0
  145. package/build/s3/consts.js +9 -0
  146. package/build/s3/consts.js.map +1 -0
  147. package/build/s3/prefix.d.ts +4 -0
  148. package/build/s3/prefix.d.ts.map +1 -0
  149. package/build/s3/prefix.js +87 -0
  150. package/build/s3/prefix.js.map +1 -0
  151. package/build/s3/sink.d.ts +6 -0
  152. package/build/s3/sink.d.ts.map +1 -0
  153. package/build/s3/sink.js +30 -0
  154. package/build/s3/sink.js.map +1 -0
  155. package/build/s3/source.d.ts +5 -0
  156. package/build/s3/source.d.ts.map +1 -0
  157. package/build/s3/source.js +81 -0
  158. package/build/s3/source.js.map +1 -0
  159. package/build/s3/types.d.ts +66 -0
  160. package/build/s3/types.d.ts.map +1 -0
  161. package/build/s3/types.js +2 -0
  162. package/build/s3/types.js.map +1 -0
  163. package/build/s3/types.local.d.ts +43 -0
  164. package/build/s3/types.local.d.ts.map +1 -0
  165. package/build/s3/types.local.js +2 -0
  166. package/build/s3/types.local.js.map +1 -0
  167. package/build/s3/upload.d.ts +4 -0
  168. package/build/s3/upload.d.ts.map +1 -0
  169. package/build/s3/upload.js +118 -0
  170. package/build/s3/upload.js.map +1 -0
  171. package/build/s3.d.ts +5 -0
  172. package/build/s3.d.ts.map +1 -0
  173. package/build/s3.js +68 -0
  174. package/build/s3.js.map +1 -0
  175. package/build/service/types.d.ts +66 -0
  176. package/build/service/types.d.ts.map +1 -0
  177. package/build/service/types.js +2 -0
  178. package/build/service/types.js.map +1 -0
  179. package/build/service/types.local.d.ts +11 -0
  180. package/build/service/types.local.d.ts.map +1 -0
  181. package/build/service/types.local.js +2 -0
  182. package/build/service/types.local.js.map +1 -0
  183. package/build/service.d.ts +6 -0
  184. package/build/service.d.ts.map +1 -0
  185. package/build/service.js +73 -0
  186. package/build/service.js.map +1 -0
  187. package/build/sinks/buffer/consts.d.ts +2 -0
  188. package/build/sinks/buffer/consts.d.ts.map +1 -0
  189. package/build/sinks/buffer/consts.js +2 -0
  190. package/build/sinks/buffer/consts.js.map +1 -0
  191. package/build/sinks/buffer/types.d.ts +11 -0
  192. package/build/sinks/buffer/types.d.ts.map +1 -0
  193. package/build/sinks/buffer/types.js +2 -0
  194. package/build/sinks/buffer/types.js.map +1 -0
  195. package/build/sinks/buffer.d.ts +4 -0
  196. package/build/sinks/buffer.d.ts.map +1 -0
  197. package/build/sinks/buffer.js +13 -0
  198. package/build/sinks/buffer.js.map +1 -0
  199. package/build/sinks/directory/types.d.ts +7 -0
  200. package/build/sinks/directory/types.d.ts.map +1 -0
  201. package/build/sinks/directory/types.js +2 -0
  202. package/build/sinks/directory/types.js.map +1 -0
  203. package/build/sinks/directory.d.ts +8 -0
  204. package/build/sinks/directory.d.ts.map +1 -0
  205. package/build/sinks/directory.js +43 -0
  206. package/build/sinks/directory.js.map +1 -0
  207. package/build/sinks/file.d.ts +5 -0
  208. package/build/sinks/file.d.ts.map +1 -0
  209. package/build/sinks/file.js +46 -0
  210. package/build/sinks/file.js.map +1 -0
  211. package/build/sinks/types.d.ts +11 -0
  212. package/build/sinks/types.d.ts.map +1 -0
  213. package/build/sinks/types.js +2 -0
  214. package/build/sinks/types.js.map +1 -0
  215. package/build/sinks/workload/consts.d.ts +5 -0
  216. package/build/sinks/workload/consts.d.ts.map +1 -0
  217. package/build/sinks/workload/consts.js +5 -0
  218. package/build/sinks/workload/consts.js.map +1 -0
  219. package/build/sinks/workload/types.d.ts +17 -0
  220. package/build/sinks/workload/types.d.ts.map +1 -0
  221. package/build/sinks/workload/types.js +2 -0
  222. package/build/sinks/workload/types.js.map +1 -0
  223. package/build/sinks/workload.d.ts +8 -0
  224. package/build/sinks/workload.d.ts.map +1 -0
  225. package/build/sinks/workload.js +51 -0
  226. package/build/sinks/workload.js.map +1 -0
  227. package/build/sources/buffer.d.ts +5 -0
  228. package/build/sources/buffer.d.ts.map +1 -0
  229. package/build/sources/buffer.js +20 -0
  230. package/build/sources/buffer.js.map +1 -0
  231. package/build/sources/file.d.ts +5 -0
  232. package/build/sources/file.d.ts.map +1 -0
  233. package/build/sources/file.js +50 -0
  234. package/build/sources/file.js.map +1 -0
  235. package/build/sources/stream.d.ts +5 -0
  236. package/build/sources/stream.d.ts.map +1 -0
  237. package/build/sources/stream.js +19 -0
  238. package/build/sources/stream.js.map +1 -0
  239. package/build/sources/types.d.ts +10 -0
  240. package/build/sources/types.d.ts.map +1 -0
  241. package/build/sources/types.js +2 -0
  242. package/build/sources/types.js.map +1 -0
  243. package/build/sources/workload/types.d.ts +29 -0
  244. package/build/sources/workload/types.d.ts.map +1 -0
  245. package/build/sources/workload/types.js +2 -0
  246. package/build/sources/workload/types.js.map +1 -0
  247. package/build/sources/workload.d.ts +7 -0
  248. package/build/sources/workload.d.ts.map +1 -0
  249. package/build/sources/workload.js +67 -0
  250. package/build/sources/workload.js.map +1 -0
  251. package/build/transfer/consts.d.ts +5 -0
  252. package/build/transfer/consts.d.ts.map +1 -0
  253. package/build/transfer/consts.js +8 -0
  254. package/build/transfer/consts.js.map +1 -0
  255. package/build/transfer/types.d.ts +49 -0
  256. package/build/transfer/types.d.ts.map +1 -0
  257. package/build/transfer/types.js +2 -0
  258. package/build/transfer/types.js.map +1 -0
  259. package/build/transfer.d.ts +4 -0
  260. package/build/transfer.d.ts.map +1 -0
  261. package/build/transfer.js +75 -0
  262. package/build/transfer.js.map +1 -0
  263. package/build/types.d.ts +99 -0
  264. package/build/types.d.ts.map +1 -0
  265. package/build/types.js +2 -0
  266. package/build/types.js.map +1 -0
  267. package/build/utils/names/consts.d.ts +5 -0
  268. package/build/utils/names/consts.d.ts.map +1 -0
  269. package/build/utils/names/consts.js +5 -0
  270. package/build/utils/names/consts.js.map +1 -0
  271. package/build/utils/names/types.d.ts +13 -0
  272. package/build/utils/names/types.d.ts.map +1 -0
  273. package/build/utils/names/types.js +2 -0
  274. package/build/utils/names/types.js.map +1 -0
  275. package/build/utils/names.d.ts +4 -0
  276. package/build/utils/names.d.ts.map +1 -0
  277. package/build/utils/names.js +60 -0
  278. package/build/utils/names.js.map +1 -0
  279. package/build/utils/paths/consts.d.ts +3 -0
  280. package/build/utils/paths/consts.d.ts.map +1 -0
  281. package/build/utils/paths/consts.js +2 -0
  282. package/build/utils/paths/consts.js.map +1 -0
  283. package/build/utils/paths/types.d.ts +20 -0
  284. package/build/utils/paths/types.d.ts.map +1 -0
  285. package/build/utils/paths/types.js +2 -0
  286. package/build/utils/paths/types.js.map +1 -0
  287. package/build/utils/paths.d.ts +4 -0
  288. package/build/utils/paths.d.ts.map +1 -0
  289. package/build/utils/paths.js +67 -0
  290. package/build/utils/paths.js.map +1 -0
  291. package/build/utils/range/types.d.ts +11 -0
  292. package/build/utils/range/types.d.ts.map +1 -0
  293. package/build/utils/range/types.js +2 -0
  294. package/build/utils/range/types.js.map +1 -0
  295. package/build/utils/range.d.ts +4 -0
  296. package/build/utils/range.d.ts.map +1 -0
  297. package/build/utils/range.js +64 -0
  298. package/build/utils/range.js.map +1 -0
  299. package/build/utils/redact/types.d.ts +16 -0
  300. package/build/utils/redact/types.d.ts.map +1 -0
  301. package/build/utils/redact/types.js +2 -0
  302. package/build/utils/redact/types.js.map +1 -0
  303. package/build/utils/redact.d.ts +4 -0
  304. package/build/utils/redact.d.ts.map +1 -0
  305. package/build/utils/redact.js +18 -0
  306. package/build/utils/redact.js.map +1 -0
  307. package/build/utils/signals/types.d.ts +17 -0
  308. package/build/utils/signals/types.d.ts.map +1 -0
  309. package/build/utils/signals/types.js +2 -0
  310. package/build/utils/signals/types.js.map +1 -0
  311. package/build/utils/signals.d.ts +4 -0
  312. package/build/utils/signals.d.ts.map +1 -0
  313. package/build/utils/signals.js +52 -0
  314. package/build/utils/signals.js.map +1 -0
  315. package/build/utils/streams/consts.d.ts +3 -0
  316. package/build/utils/streams/consts.d.ts.map +1 -0
  317. package/build/utils/streams/consts.js +3 -0
  318. package/build/utils/streams/consts.js.map +1 -0
  319. package/build/utils/streams/types.d.ts +59 -0
  320. package/build/utils/streams/types.d.ts.map +1 -0
  321. package/build/utils/streams/types.js +2 -0
  322. package/build/utils/streams/types.js.map +1 -0
  323. package/build/utils/streams.d.ts +4 -0
  324. package/build/utils/streams.d.ts.map +1 -0
  325. package/build/utils/streams.js +167 -0
  326. package/build/utils/streams.js.map +1 -0
  327. package/build/utils/tree/types.d.ts +6 -0
  328. package/build/utils/tree/types.d.ts.map +1 -0
  329. package/build/utils/tree/types.js +2 -0
  330. package/build/utils/tree/types.js.map +1 -0
  331. package/build/utils/tree.d.ts +4 -0
  332. package/build/utils/tree.d.ts.map +1 -0
  333. package/build/utils/tree.js +14 -0
  334. package/build/utils/tree.js.map +1 -0
  335. package/build/workspace/consts.d.ts +12 -0
  336. package/build/workspace/consts.d.ts.map +1 -0
  337. package/build/workspace/consts.js +12 -0
  338. package/build/workspace/consts.js.map +1 -0
  339. package/build/workspace/consts.local.d.ts +3 -0
  340. package/build/workspace/consts.local.d.ts.map +1 -0
  341. package/build/workspace/consts.local.js +3 -0
  342. package/build/workspace/consts.local.js.map +1 -0
  343. package/build/workspace/fs.d.ts +4 -0
  344. package/build/workspace/fs.d.ts.map +1 -0
  345. package/build/workspace/fs.js +45 -0
  346. package/build/workspace/fs.js.map +1 -0
  347. package/build/workspace/scope.d.ts +6 -0
  348. package/build/workspace/scope.d.ts.map +1 -0
  349. package/build/workspace/scope.js +180 -0
  350. package/build/workspace/scope.js.map +1 -0
  351. package/build/workspace/types.d.ts +66 -0
  352. package/build/workspace/types.d.ts.map +1 -0
  353. package/build/workspace/types.js +2 -0
  354. package/build/workspace/types.js.map +1 -0
  355. package/build/workspace/types.local.d.ts +20 -0
  356. package/build/workspace/types.local.d.ts.map +1 -0
  357. package/build/workspace/types.local.js +2 -0
  358. package/build/workspace/types.local.js.map +1 -0
  359. package/build/workspace.d.ts +7 -0
  360. package/build/workspace.d.ts.map +1 -0
  361. package/build/workspace.js +87 -0
  362. package/build/workspace.js.map +1 -0
  363. package/package.json +61 -4
  364. package/src/archive/consts.ts +28 -0
  365. package/src/archive/formats.ts +60 -0
  366. package/src/archive/guard.ts +68 -0
  367. package/src/archive/ratio.ts +35 -0
  368. package/src/archive/tar.ts +147 -0
  369. package/src/archive/types.local.ts +72 -0
  370. package/src/archive/types.ts +107 -0
  371. package/src/archive/zip.ts +142 -0
  372. package/src/archive.ts +298 -0
  373. package/src/backed-workspace/types.ts +72 -0
  374. package/src/backed-workspace.ts +85 -0
  375. package/src/consts.local.ts +2 -0
  376. package/src/consts.ts +2 -0
  377. package/src/errors.ts +128 -0
  378. package/src/http/connector.ts +136 -0
  379. package/src/http/consts.ts +13 -0
  380. package/src/http/source.ts +89 -0
  381. package/src/http/types.local.ts +23 -0
  382. package/src/http/types.ts +74 -0
  383. package/src/http.ts +276 -0
  384. package/src/index.ts +65 -0
  385. package/src/network/consts.ts +22 -0
  386. package/src/network/types.ts +45 -0
  387. package/src/network.ts +179 -0
  388. package/src/proxy/consts.ts +11 -0
  389. package/src/proxy/endpoint.ts +28 -0
  390. package/src/proxy/http.ts +108 -0
  391. package/src/proxy/router.ts +93 -0
  392. package/src/proxy/socks.ts +48 -0
  393. package/src/proxy/types.ts +114 -0
  394. package/src/resolvers/google-drive/consts.ts +22 -0
  395. package/src/resolvers/google-drive/types.ts +22 -0
  396. package/src/resolvers/google-drive.ts +153 -0
  397. package/src/resolvers/types.ts +45 -0
  398. package/src/s3/consts.ts +12 -0
  399. package/src/s3/prefix.ts +100 -0
  400. package/src/s3/sink.ts +36 -0
  401. package/src/s3/source.ts +90 -0
  402. package/src/s3/types.local.ts +49 -0
  403. package/src/s3/types.ts +70 -0
  404. package/src/s3/upload.ts +130 -0
  405. package/src/s3.ts +83 -0
  406. package/src/service/types.local.ts +9 -0
  407. package/src/service/types.ts +71 -0
  408. package/src/service.ts +97 -0
  409. package/src/sinks/buffer/consts.ts +1 -0
  410. package/src/sinks/buffer/types.ts +12 -0
  411. package/src/sinks/buffer.ts +18 -0
  412. package/src/sinks/directory/types.ts +7 -0
  413. package/src/sinks/directory.ts +49 -0
  414. package/src/sinks/file.ts +52 -0
  415. package/src/sinks/types.ts +12 -0
  416. package/src/sinks/workload/consts.ts +5 -0
  417. package/src/sinks/workload/types.ts +17 -0
  418. package/src/sinks/workload.ts +59 -0
  419. package/src/sources/buffer.ts +27 -0
  420. package/src/sources/file.ts +57 -0
  421. package/src/sources/stream.ts +26 -0
  422. package/src/sources/types.ts +12 -0
  423. package/src/sources/workload/types.ts +31 -0
  424. package/src/sources/workload.ts +79 -0
  425. package/src/transfer/consts.ts +10 -0
  426. package/src/transfer/types.ts +55 -0
  427. package/src/transfer.ts +89 -0
  428. package/src/types.ts +106 -0
  429. package/src/utils/names/consts.ts +5 -0
  430. package/src/utils/names/types.ts +12 -0
  431. package/src/utils/names.ts +70 -0
  432. package/src/utils/paths/consts.ts +3 -0
  433. package/src/utils/paths/types.ts +20 -0
  434. package/src/utils/paths.ts +75 -0
  435. package/src/utils/range/types.ts +11 -0
  436. package/src/utils/range.ts +80 -0
  437. package/src/utils/redact/types.ts +16 -0
  438. package/src/utils/redact.ts +23 -0
  439. package/src/utils/signals/types.ts +17 -0
  440. package/src/utils/signals.ts +63 -0
  441. package/src/utils/streams/consts.ts +2 -0
  442. package/src/utils/streams/types.ts +65 -0
  443. package/src/utils/streams.ts +188 -0
  444. package/src/utils/tree/types.ts +6 -0
  445. package/src/utils/tree.ts +18 -0
  446. package/src/workspace/consts.local.ts +2 -0
  447. package/src/workspace/consts.ts +14 -0
  448. package/src/workspace/fs.ts +48 -0
  449. package/src/workspace/scope.ts +196 -0
  450. package/src/workspace/types.local.ts +21 -0
  451. package/src/workspace/types.ts +71 -0
  452. package/src/workspace.ts +102 -0
  453. package/tests/archive.spec.ts +134 -0
  454. package/tests/backed.spec.ts +147 -0
  455. package/tests/context.ts +114 -0
  456. package/tests/fixtures.ts +190 -0
  457. package/tests/google-drive.spec.ts +76 -0
  458. package/tests/harness/drive.ts +92 -0
  459. package/tests/harness/http-proxy.ts +96 -0
  460. package/tests/harness/origin.ts +134 -0
  461. package/tests/harness/socks5.ts +135 -0
  462. package/tests/harness/workload.ts +118 -0
  463. package/tests/http.spec.ts +101 -0
  464. package/tests/inspector.spec.ts +40 -0
  465. package/tests/live.spec.ts +27 -0
  466. package/tests/network.spec.ts +79 -0
  467. package/tests/proxy.spec.ts +149 -0
  468. package/tests/s3.spec.ts +133 -0
  469. package/tests/service.spec.ts +77 -0
  470. package/tests/sources-sinks.spec.ts +96 -0
  471. package/tests/transfer.spec.ts +99 -0
  472. package/tests/tsconfig.json +12 -0
  473. package/tests/workload.spec.ts +140 -0
  474. package/tests/workspace.spec.ts +158 -0
  475. package/tsconfig.json +16 -0
@@ -0,0 +1,96 @@
1
+ import { connect, createServer } from 'node:net'
2
+ import type { AddressInfo, Server, Socket } from 'node:net'
3
+
4
+ export interface ProxyRecord {
5
+ method: string
6
+ target: string
7
+ authorization?: string
8
+ }
9
+
10
+ export interface LocalHttpProxy {
11
+ readonly port: number
12
+ readonly url: string
13
+ records: ProxyRecord[]
14
+ stop: () => void
15
+ }
16
+
17
+ export interface LocalHttpProxyOptions {
18
+ username?: string
19
+ password?: string
20
+ }
21
+
22
+ /** A CONNECT and forward HTTP proxy with optional Basic auth; records every request line. */
23
+ export const startHttpProxy = (options: LocalHttpProxyOptions = {}): Promise<LocalHttpProxy> => new Promise(resolve => {
24
+ const records: ProxyRecord[] = []
25
+ const sockets = new Set<Socket>()
26
+ const expected = options.username != null
27
+ ? `Basic ${Buffer.from(`${options.username}:${options.password ?? ''}`).toString('base64')}`
28
+ : undefined
29
+
30
+ const server: Server = createServer(client => {
31
+ sockets.add(client)
32
+ client.on('close', () => sockets.delete(client))
33
+ client.on('error', () => undefined)
34
+ let buffer = Buffer.alloc(0)
35
+ const onData = (chunk: Buffer): void => {
36
+ buffer = Buffer.concat([buffer, chunk])
37
+ const end = buffer.indexOf('\r\n\r\n')
38
+ if (end === -1) {
39
+ return
40
+ }
41
+ client.removeListener('data', onData)
42
+ const [requestLine, ...headerLines] = buffer.subarray(0, end).toString('latin1').split('\r\n')
43
+ const rest = buffer.subarray(end + 4)
44
+ const [method, target] = requestLine.split(' ')
45
+ const authorization = headerLines.find(line => /^proxy-authorization:/i.test(line))?.replace(/^[^:]+:\s*/, '')
46
+ records.push({ method, target, authorization })
47
+ if (expected != null && authorization !== expected) {
48
+ client.end('HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic\r\nContent-Length: 0\r\n\r\n')
49
+ return
50
+ }
51
+ const upstreamOf = (host: string, port: number, ready: (upstream: Socket) => void): void => {
52
+ const upstream = connect(port, host, () => ready(upstream))
53
+ sockets.add(upstream)
54
+ upstream.on('close', () => { sockets.delete(upstream); client.destroy() })
55
+ upstream.on('error', () => client.destroy())
56
+ client.on('close', () => upstream.destroy())
57
+ }
58
+ if (method === 'CONNECT') {
59
+ const separator = target.lastIndexOf(':')
60
+ upstreamOf(target.slice(0, separator).replace(/^\[|\]$/g, ''), Number(target.slice(separator + 1)), upstream => {
61
+ client.write('HTTP/1.1 200 Connection Established\r\n\r\n')
62
+ if (rest.length > 0) {
63
+ upstream.write(rest)
64
+ }
65
+ client.pipe(upstream)
66
+ upstream.pipe(client)
67
+ })
68
+ return
69
+ }
70
+ const url = new URL(target)
71
+ upstreamOf(url.hostname, Number(url.port !== '' ? url.port : 80), upstream => {
72
+ const headers = headerLines.filter(line => !/^proxy-authorization:/i.test(line))
73
+ upstream.write(`${method} ${url.pathname}${url.search} HTTP/1.1\r\n${headers.join('\r\n')}\r\n\r\n`)
74
+ if (rest.length > 0) {
75
+ upstream.write(rest)
76
+ }
77
+ client.pipe(upstream)
78
+ upstream.pipe(client)
79
+ })
80
+ }
81
+ client.on('data', onData)
82
+ })
83
+
84
+ server.listen(0, '127.0.0.1', () => {
85
+ const port = (server.address() as AddressInfo).port
86
+ resolve({
87
+ port,
88
+ url: `http://127.0.0.1:${port}`,
89
+ records,
90
+ stop: () => {
91
+ sockets.forEach(socket => socket.destroy())
92
+ server.close()
93
+ },
94
+ })
95
+ })
96
+ })
@@ -0,0 +1,134 @@
1
+ import { createServer } from 'node:net'
2
+ import type { AddressInfo, Server } from 'node:net'
3
+ import { gzipSync } from 'node:zlib'
4
+
5
+ export interface OriginFile {
6
+ bytes: Uint8Array
7
+ type?: string
8
+ disposition?: string
9
+ etag?: string
10
+ }
11
+
12
+ export interface OriginRequest {
13
+ path: string
14
+ headers: Record<string, string>
15
+ }
16
+
17
+ export interface Origin {
18
+ readonly base: string
19
+ url: (path: string) => string
20
+ files: Map<string, OriginFile>
21
+ /** Body bytes served per file name. */
22
+ served: Map<string, number>
23
+ requests: OriginRequest[]
24
+ stop: () => void
25
+ }
26
+
27
+ export interface StartOriginOptions {
28
+ tls?: { key: string, cert: string }
29
+ }
30
+
31
+ /**
32
+ * A local HTTP origin: `/files/<name>` (Range + ETag + If-Range), `/norange/<name>`, `/gzip/<name>`
33
+ * (Content-Encoding), `/redirect/<n>`, `/go?to=&status=`, `/status/<code>`, `/headers`,
34
+ * `/stall-headers`, `/stall-body`.
35
+ */
36
+ export const startOrigin = (options: StartOriginOptions = {}): Origin => {
37
+ const files = new Map<string, OriginFile>()
38
+ const served = new Map<string, number>()
39
+ const requests: OriginRequest[] = []
40
+ const count = (name: string, bytes: number): void => { served.set(name, (served.get(name) ?? 0) + bytes) }
41
+
42
+ const server = Bun.serve({
43
+ port: 0,
44
+ hostname: '127.0.0.1',
45
+ tls: options.tls,
46
+ idleTimeout: 0,
47
+ fetch: async request => {
48
+ const url = new URL(request.url)
49
+ requests.push({ path: `${url.pathname}${url.search}`, headers: Object.fromEntries(request.headers) })
50
+ const [, route, ...rest] = url.pathname.split('/')
51
+ const name = decodeURIComponent(rest.join('/'))
52
+ switch (route) {
53
+ case 'files':
54
+ case 'norange': {
55
+ const file = files.get(name)
56
+ if (file == null) {
57
+ return new Response('missing', { status: 404 })
58
+ }
59
+ const length = file.bytes.length
60
+ const etag = file.etag ?? `"${name}-${length}"`
61
+ const headers: Record<string, string> = { 'content-type': file.type ?? 'application/octet-stream', etag }
62
+ if (file.disposition != null) {
63
+ headers['content-disposition'] = file.disposition
64
+ }
65
+ const range = request.headers.get('range')
66
+ const ifRange = request.headers.get('if-range')
67
+ if (route === 'files') {
68
+ headers['accept-ranges'] = 'bytes'
69
+ }
70
+ if (route === 'files' && range != null && (ifRange == null || ifRange === etag)) {
71
+ const match = /bytes=(\d+)-(\d*)/.exec(range)
72
+ const start = Number(match?.[1] ?? 0)
73
+ const end = match?.[2] != null && match[2] !== '' ? Math.min(Number(match[2]), length - 1) : length - 1
74
+ if (start >= length) {
75
+ return new Response(null, { status: 416, headers: { 'content-range': `bytes */${length}` } })
76
+ }
77
+ const slice = file.bytes.subarray(start, end + 1)
78
+ count(name, slice.length)
79
+ return new Response(slice, { status: 206, headers: { ...headers, 'content-range': `bytes ${start}-${end}/${length}` } })
80
+ }
81
+ count(name, length)
82
+ return new Response(file.bytes, { headers })
83
+ }
84
+ case 'gzip': {
85
+ const file = files.get(name)
86
+ if (file == null) {
87
+ return new Response('missing', { status: 404 })
88
+ }
89
+ return new Response(gzipSync(file.bytes), { headers: { 'content-encoding': 'gzip', 'content-type': file.type ?? 'application/octet-stream' } })
90
+ }
91
+ case 'redirect': {
92
+ const left = Number(rest[0])
93
+ return left > 0
94
+ ? new Response(null, { status: 302, headers: { location: `/redirect/${left - 1}` } })
95
+ : new Response('arrived', { headers: { 'content-type': 'text/plain' } })
96
+ }
97
+ case 'go':
98
+ return new Response(null, { status: Number(url.searchParams.get('status') ?? 302), headers: { location: url.searchParams.get('to') ?? '/' } })
99
+ case 'status':
100
+ return new Response('status page', { status: Number(rest[0]) })
101
+ case 'headers':
102
+ return Response.json(Object.fromEntries(request.headers))
103
+ case 'stall-headers':
104
+ return await new Promise<Response>(() => undefined)
105
+ case 'stall-body':
106
+ return new Response(new ReadableStream({ start: controller => { controller.enqueue(new Uint8Array([1, 2, 3])) } }), {
107
+ headers: { 'content-type': 'application/octet-stream' },
108
+ })
109
+ default:
110
+ return new Response('not found', { status: 404 })
111
+ }
112
+ },
113
+ })
114
+ const base = `${options.tls != null ? 'https' : 'http'}://127.0.0.1:${server.port}`
115
+
116
+ return { base, url: path => `${base}${path}`, files, served, requests, stop: () => { server.stop(true) } }
117
+ }
118
+
119
+ export interface RawServer {
120
+ readonly base: string
121
+ stop: () => void
122
+ }
123
+
124
+ /** A raw TCP server answering one fixed response — for bodies shorter than their Content-Length. */
125
+ export const startRawServer = (response: string): Promise<RawServer> => new Promise(resolve => {
126
+ const server: Server = createServer(socket => {
127
+ socket.once('data', () => socket.end(response))
128
+ socket.on('error', () => undefined)
129
+ })
130
+ server.listen(0, '127.0.0.1', () => {
131
+ const port = (server.address() as AddressInfo).port
132
+ resolve({ base: `http://127.0.0.1:${port}`, stop: () => { server.close() } })
133
+ })
134
+ })
@@ -0,0 +1,135 @@
1
+ import { connect, createServer } from 'node:net'
2
+ import type { AddressInfo, Server, Socket } from 'node:net'
3
+
4
+ export interface SocksRecord {
5
+ /** 1 IPv4, 3 domain name, 4 IPv6. */
6
+ atyp: number
7
+ address: string
8
+ port: number
9
+ username?: string
10
+ }
11
+
12
+ export interface LocalSocksProxy {
13
+ readonly port: number
14
+ records: SocksRecord[]
15
+ stop: () => void
16
+ }
17
+
18
+ export interface LocalSocksOptions {
19
+ username?: string
20
+ password?: string
21
+ }
22
+
23
+ /** A SOCKS5 CONNECT server, with optional user/password auth; records every destination. */
24
+ export const startSocksProxy = (options: LocalSocksOptions = {}): Promise<LocalSocksProxy> => new Promise(resolve => {
25
+ const records: SocksRecord[] = []
26
+ const sockets = new Set<Socket>()
27
+
28
+ const server: Server = createServer(client => {
29
+ sockets.add(client)
30
+ client.on('close', () => sockets.delete(client))
31
+ client.on('error', () => undefined)
32
+ let buffer = Buffer.alloc(0)
33
+ let stage: 'greeting' | 'auth' | 'request' | 'pipe' = 'greeting'
34
+ let username: string | undefined
35
+
36
+ const step = (): void => {
37
+ if (stage === 'greeting') {
38
+ if (buffer.length < 2 || buffer.length < 2 + buffer[1]) {
39
+ return
40
+ }
41
+ const methods = [...buffer.subarray(2, 2 + buffer[1])]
42
+ buffer = buffer.subarray(2 + buffer[1])
43
+ if (options.username != null) {
44
+ if (!methods.includes(2)) {
45
+ client.end(Buffer.from([5, 0xff]))
46
+ return
47
+ }
48
+ client.write(Buffer.from([5, 2]))
49
+ stage = 'auth'
50
+ } else {
51
+ client.write(Buffer.from([5, 0]))
52
+ stage = 'request'
53
+ }
54
+ step()
55
+ return
56
+ }
57
+ if (stage === 'auth') {
58
+ if (buffer.length < 2) {
59
+ return
60
+ }
61
+ const userLength = buffer[1]
62
+ if (buffer.length < 3 + userLength || buffer.length < 3 + userLength + buffer[2 + userLength]) {
63
+ return
64
+ }
65
+ const passLength = buffer[2 + userLength]
66
+ username = buffer.subarray(2, 2 + userLength).toString()
67
+ const password = buffer.subarray(3 + userLength, 3 + userLength + passLength).toString()
68
+ buffer = buffer.subarray(3 + userLength + passLength)
69
+ if (username !== options.username || password !== options.password) {
70
+ client.end(Buffer.from([1, 1]))
71
+ return
72
+ }
73
+ client.write(Buffer.from([1, 0]))
74
+ stage = 'request'
75
+ step()
76
+ return
77
+ }
78
+ if (stage === 'request') {
79
+ if (buffer.length < 5) {
80
+ return
81
+ }
82
+ const atyp = buffer[3]
83
+ let address: string
84
+ let offset: number
85
+ if (atyp === 1) {
86
+ if (buffer.length < 10) return
87
+ address = [...buffer.subarray(4, 8)].join('.')
88
+ offset = 8
89
+ } else if (atyp === 3) {
90
+ const length = buffer[4]
91
+ if (buffer.length < 7 + length) return
92
+ address = buffer.subarray(5, 5 + length).toString()
93
+ offset = 5 + length
94
+ } else {
95
+ if (buffer.length < 22) return
96
+ const groups: string[] = []
97
+ for (let index = 4; index < 20; index += 2) groups.push(buffer.readUInt16BE(index).toString(16))
98
+ address = groups.join(':')
99
+ offset = 20
100
+ }
101
+ const port = buffer.readUInt16BE(offset)
102
+ const rest = buffer.subarray(offset + 2)
103
+ records.push({ atyp, address, port, username })
104
+ stage = 'pipe'
105
+ client.removeAllListeners('data')
106
+ const upstream = connect(port, address, () => {
107
+ client.write(Buffer.from([5, 0, 0, 1, 0, 0, 0, 0, 0, 0]))
108
+ if (rest.length > 0) upstream.write(rest)
109
+ client.pipe(upstream)
110
+ upstream.pipe(client)
111
+ })
112
+ sockets.add(upstream)
113
+ upstream.on('close', () => { sockets.delete(upstream); client.destroy() })
114
+ upstream.on('error', () => client.end(Buffer.from([5, 5, 0, 1, 0, 0, 0, 0, 0, 0])))
115
+ client.on('close', () => upstream.destroy())
116
+ }
117
+ }
118
+
119
+ client.on('data', (chunk: Buffer) => {
120
+ buffer = Buffer.concat([buffer, chunk])
121
+ step()
122
+ })
123
+ })
124
+
125
+ server.listen(0, '127.0.0.1', () => {
126
+ resolve({
127
+ port: (server.address() as AddressInfo).port,
128
+ records,
129
+ stop: () => {
130
+ sockets.forEach(socket => socket.destroy())
131
+ server.close()
132
+ },
133
+ })
134
+ })
135
+ })
@@ -0,0 +1,118 @@
1
+ import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'
2
+ import { dirname, relative, resolve } from 'node:path'
3
+ import { randomUUID } from 'node:crypto'
4
+ import type { WorkloadReader, WorkloadWriter } from '../../src/index.js'
5
+
6
+ export interface LocalWorkload {
7
+ readonly url: string
8
+ /** The sandbox the writes land in. */
9
+ readonly sandbox: string
10
+ /** Answer the next `count` commands with a 500. */
11
+ failNext: (count: number) => void
12
+ /** Commands received. */
13
+ commands: number
14
+ stop: () => void
15
+ }
16
+
17
+ /**
18
+ * A stand-in for a Viable publisher's `POST /command/`: the `writeBinaryFile` contract with its real
19
+ * limits — base64 of at most 16 MiB characters, a 20 MiB body, a path confined to the sandbox, an
20
+ * atomic temp-and-rename write — and its read twin `readBinaryFile { filePath } → { base64 }`.
21
+ */
22
+ export const startWorkload = (sandbox: string): LocalWorkload => {
23
+ let failures = 0
24
+ const state = { commands: 0 }
25
+ // The publisher's check: the alphabet with trailing padding over a length divisible by four.
26
+ const isBase64 = (value: string): boolean => value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(value)
27
+ const confined = (filePath: string): string | null => {
28
+ const target = resolve(sandbox, filePath.replace(/^\/var\/sandbox\/?/, ''))
29
+ const inside = relative(sandbox, target)
30
+ return inside === '' || inside.startsWith('..') ? null : target
31
+ }
32
+
33
+ const server = Bun.serve({
34
+ port: 0,
35
+ hostname: '127.0.0.1',
36
+ maxRequestBodySize: 20 * 1024 * 1024,
37
+ fetch: async request => {
38
+ const url = new URL(request.url)
39
+ if (request.method !== 'POST' || url.pathname !== '/command/') {
40
+ return new Response('not found', { status: 404 })
41
+ }
42
+ state.commands++
43
+ if (failures > 0) {
44
+ failures--
45
+ return new Response('busy', { status: 500 })
46
+ }
47
+ const payload = await request.json() as { type: string, command: string, args?: { filePath?: unknown, base64?: unknown } }
48
+ const filePath = payload.args?.filePath
49
+ const data = payload.args?.base64
50
+ if (payload.type === 'files' && payload.command === 'readBinaryFile') {
51
+ const target = typeof filePath === 'string' ? confined(filePath) : null
52
+ if (target == null) {
53
+ return Response.json({ error: 'outside sandbox' }, { status: 400 })
54
+ }
55
+ const stats = await stat(target).catch(() => null)
56
+ if (stats == null || !stats.isFile()) {
57
+ return Response.json({ error: 'not found' }, { status: 404 })
58
+ }
59
+ return Response.json({ base64: (await readFile(target)).toString('base64') })
60
+ }
61
+ if (payload.type !== 'files' || payload.command !== 'writeBinaryFile' || typeof filePath !== 'string'
62
+ || typeof data !== 'string' || data.length > 16 * 1024 * 1024 || !isBase64(data)) {
63
+ return Response.json({ error: 'Invalid binary media payload' }, { status: 400 })
64
+ }
65
+ const target = confined(filePath)
66
+ if (target == null) {
67
+ return Response.json({ error: 'outside sandbox' }, { status: 400 })
68
+ }
69
+ await mkdir(dirname(target), { recursive: true })
70
+ const temporary = `${target}.${randomUUID()}.tmp`
71
+ try {
72
+ await writeFile(temporary, Buffer.from(data, 'base64'), { flag: 'wx' })
73
+ await rename(temporary, target)
74
+ } finally {
75
+ await rm(temporary, { force: true })
76
+ }
77
+ return Response.json({})
78
+ },
79
+ })
80
+
81
+ return {
82
+ url: `http://127.0.0.1:${server.port}/command/`,
83
+ sandbox,
84
+ failNext: count => { failures = count },
85
+ get commands () { return state.commands },
86
+ set commands (value: number) { state.commands = value },
87
+ stop: () => { server.stop(true) },
88
+ }
89
+ }
90
+
91
+ /** The agent side of the contract: what viable-agent's FileHelper does, over plain fetch. */
92
+ export const workloadWriter = (url: string): WorkloadWriter => ({
93
+ writeBinaryFile: async (filePath: string, base64: string): Promise<void> => {
94
+ const response = await fetch(url, {
95
+ method: 'POST',
96
+ headers: { 'content-type': 'application/json' },
97
+ body: JSON.stringify({ type: 'files', command: 'writeBinaryFile', args: { filePath, base64 } }),
98
+ })
99
+ if (!response.ok) {
100
+ throw new Error(`workload answered ${response.status}`)
101
+ }
102
+ },
103
+ })
104
+
105
+ /** The agent side of the read: what viable-agent's FileHelper does, over plain fetch. */
106
+ export const workloadReader = (url: string): WorkloadReader => ({
107
+ readBinaryFile: async (filePath: string): Promise<string> => {
108
+ const response = await fetch(url, {
109
+ method: 'POST',
110
+ headers: { 'content-type': 'application/json' },
111
+ body: JSON.stringify({ type: 'files', command: 'readBinaryFile', args: { filePath } }),
112
+ })
113
+ if (!response.ok) {
114
+ throw new Error(`workload answered ${response.status}`)
115
+ }
116
+ return (await response.json() as { base64: string }).base64
117
+ },
118
+ })
@@ -0,0 +1,101 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
2
+ import { gzipSync } from 'node:zlib'
3
+ import { HttpError, LimitError, SourceError } from '../src/index.js'
4
+ import { streamUtils } from '../src/utils/streams.js'
5
+ import { startOrigin, startRawServer } from './harness/origin.js'
6
+ import type { Origin } from './harness/origin.js'
7
+ import { localClient } from './context.js'
8
+ import { noise } from './fixtures.js'
9
+
10
+ describe('@owlmeans/file-streams — HTTP client', () => {
11
+ let origin: Origin
12
+ let other: Origin
13
+ beforeAll(() => {
14
+ origin = startOrigin()
15
+ other = startOrigin()
16
+ origin.files.set('report.pdf', {
17
+ bytes: Buffer.from('%PDF-1.4 body %%EOF'), type: 'application/pdf; charset=binary',
18
+ disposition: 'attachment; filename="fallback.pdf"; filename*=UTF-8\'\'r%C3%A9sum%C3%A9.pdf',
19
+ })
20
+ origin.files.set('big.bin', { bytes: noise(300_000) })
21
+ })
22
+ afterAll(() => {
23
+ origin.stop()
24
+ other.stop()
25
+ })
26
+
27
+ test('answers info from the response and reads ranges where the server serves them', async () => {
28
+ const client = localClient()
29
+ const response = await client.request(origin.url('/files/report.pdf'))
30
+ expect(response.info).toMatchObject({ name: 'résumé.pdf', size: 19, mime: 'application/pdf' })
31
+ expect((await streamUtils.collect(response.body, 100)).toString()).toBe('%PDF-1.4 body %%EOF')
32
+ const head = await client.request(origin.url('/files/report.pdf'), { method: 'HEAD' })
33
+ expect(head.status).toBe(200)
34
+
35
+ const ranged = client.source(origin.url('/files/big.bin'))
36
+ const reader = await ranged.ranges()
37
+ expect(reader?.size).toBe(300_000)
38
+ expect(Buffer.from(await reader!.read(1000, 16)).equals(noise(300_000).subarray(1000, 1016))).toBe(true)
39
+ expect(await client.source(origin.url('/norange/big.bin')).ranges()).toBeNull()
40
+
41
+ origin.files.set('changing.bin', { bytes: noise(1000), etag: '"v1"' })
42
+ const changing = client.source(origin.url('/files/changing.bin'))
43
+ const changingReader = await changing.ranges()
44
+ origin.files.set('changing.bin', { bytes: noise(1000, 2), etag: '"v2"' })
45
+ await expect(changingReader!.read(0, 10)).rejects.toBeInstanceOf(SourceError)
46
+ })
47
+
48
+ test('follows redirects within limits and drops credentials on another origin', async () => {
49
+ const client = localClient()
50
+ const arrived = await client.request(origin.url('/redirect/3'))
51
+ expect(arrived.redirects).toBe(3)
52
+ expect((await streamUtils.collect(arrived.body, 100)).toString()).toBe('arrived')
53
+ await expect(client.request(origin.url('/redirect/9'))).rejects.toThrow('http:redirects')
54
+
55
+ const headers = { authorization: 'Bearer secret', cookie: 'sid=1', 'x-api-key': 'k' }
56
+ const sensitive = localClient({ sensitiveHeaders: ['x-api-key'] })
57
+ const crossed = await sensitive.request(origin.url(`/go?to=${encodeURIComponent(other.url('/headers'))}`), { headers })
58
+ const seen = JSON.parse((await streamUtils.collect(crossed.body, 10_000)).toString()) as Record<string, string>
59
+ expect(seen.authorization).toBeUndefined()
60
+ expect(seen.cookie).toBeUndefined()
61
+ expect(seen['x-api-key']).toBeUndefined()
62
+
63
+ const same = await sensitive.request(origin.url('/go?to=/headers'), { headers })
64
+ const kept = JSON.parse((await streamUtils.collect(same.body, 10_000)).toString()) as Record<string, string>
65
+ expect(kept.authorization).toBe('Bearer secret')
66
+ })
67
+
68
+ test('decodes transport gzip but never a gzip file, and refuses truncated bodies', async () => {
69
+ origin.files.set('page.txt', { bytes: Buffer.from('hello '.repeat(100)), type: 'text/plain' })
70
+ origin.files.set('bundle.tar.gz', { bytes: Buffer.from('tar bytes'), type: 'application/gzip' })
71
+ const client = localClient()
72
+ const page = await client.request(origin.url('/gzip/page.txt'))
73
+ expect((await streamUtils.collect(page.body, 10_000)).toString()).toBe('hello '.repeat(100))
74
+ const bundle = await client.request(origin.url('/gzip/bundle.tar.gz'))
75
+ expect(await streamUtils.collect(bundle.body, 10_000)).toEqual(gzipSync(Buffer.from('tar bytes')))
76
+
77
+ const raw = await startRawServer('HTTP/1.1 200 OK\r\nContent-Length: 100\r\nContent-Type: application/octet-stream\r\nConnection: close\r\n\r\n0123456789')
78
+ try {
79
+ const truncated = await client.request(`${raw.base}/x`)
80
+ await expect(streamUtils.collect(truncated.body, 1000)).rejects.toThrow()
81
+ } finally {
82
+ raw.stop()
83
+ }
84
+ })
85
+
86
+ test('times out, aborts and reports statuses', async () => {
87
+ const client = localClient({ timeouts: { headersMs: 300, idleMs: 300 } })
88
+ await expect(client.request(origin.url('/stall-headers'))).rejects.toThrow('http:headers-timeout')
89
+ const stalled = await client.request(origin.url('/stall-body'))
90
+ await expect(streamUtils.collect(stalled.body, 1000)).rejects.toBeInstanceOf(LimitError)
91
+
92
+ const controller = new AbortController()
93
+ const pending = client.request(origin.url('/stall-headers'), { signal: controller.signal })
94
+ controller.abort(new Error('caller gave up'))
95
+ await expect(pending).rejects.toThrow('caller gave up')
96
+
97
+ const missing = client.request(origin.url('/status/404'))
98
+ await expect(missing).rejects.toBeInstanceOf(HttpError)
99
+ await missing.catch((error: HttpError) => expect(error.status).toBe(404))
100
+ })
101
+ })
@@ -0,0 +1,40 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
2
+ import * as inspector from '@owlmeans/file-inspector'
3
+ import { createBufferSource, createFileInspector, FileKind, FileKindError, FileMimicryError, fileInspector } from '../src/index.js'
4
+ import { bigDocxOf, cfbOf, CLSID, ELF, PNG } from './fixtures.js'
5
+ import { startOrigin } from './harness/origin.js'
6
+ import type { Origin } from './harness/origin.js'
7
+ import { localClient } from './context.js'
8
+
9
+ describe('@owlmeans/file-streams — inspector', () => {
10
+ let origin: Origin
11
+ beforeAll(() => { origin = startOrigin() })
12
+ afterAll(() => origin.stop())
13
+
14
+ test('re-exports @owlmeans/file-inspector, and its probe reads file-streams sources as they are', async () => {
15
+ expect([fileInspector, createFileInspector, FileKind, FileMimicryError, FileKindError])
16
+ .toEqual([inspector.fileInspector, inspector.createFileInspector, inspector.FileKind, inspector.FileMimicryError, inspector.FileKindError])
17
+ expect(await fileInspector.probe(createBufferSource(PNG, { name: 'dot.png' }))).toMatchObject({ status: 'match', detected: { ext: 'png' } })
18
+ await expect(fileInspector.check(createBufferSource(ELF, { name: 'cat.png' }))).rejects.toBeInstanceOf(FileMimicryError)
19
+ })
20
+
21
+ test('probes remote files through ranges within the budget, and heads without them', async () => {
22
+ origin.files.set('big.docx', { bytes: await bigDocxOf(20 * 1024 * 1024) })
23
+ origin.files.set('deep.doc', { bytes: cfbOf(CLSID.doc, 40, 41) })
24
+ const client = localClient()
25
+
26
+ const ranged = await fileInspector.probe(client.source(origin.url('/files/big.docx')))
27
+ expect(ranged).toMatchObject({ status: 'match', detected: { ext: 'docx' }, probe: { randomAccess: true } })
28
+ expect(ranged.probe.bytesRead).toBeLessThanOrEqual(1024 * 1024)
29
+ expect(origin.served.get('big.docx') ?? 0).toBeLessThan(2 * 1024 * 1024)
30
+
31
+ const headOnly = await fileInspector.probe(client.source(origin.url('/norange/big.docx')))
32
+ expect(headOnly.probe.randomAccess).toBe(false)
33
+ expect(headOnly.status).toBe('inconclusive')
34
+ expect(headOnly.reasons).toContain('head-only')
35
+
36
+ const small = createFileInspector({ sampleBytes: 4096 })
37
+ expect((await small.probe(client.source(origin.url('/files/deep.doc')))).detected?.ext).toBe('doc')
38
+ expect((await small.probe(client.source(origin.url('/norange/deep.doc')))).reasons).toContain('head-only')
39
+ }, 60_000)
40
+ })
@@ -0,0 +1,27 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { isSkip } from '@owlmeans/test'
3
+ import { createHttpClient, fileInspector, FileKind, httpClient } from '../src/index.js'
4
+ import { streamUtils } from '../src/utils/streams.js'
5
+ import { live } from './context.js'
6
+
7
+ /** Opt-in: real internet downloads (`FILE_STREAMS_LIVE=1`), and a public Drive file (`FILE_STREAMS_LIVE_DRIVE_URL`). */
8
+ describe('@owlmeans/file-streams — live internet', () => {
9
+ const internet = isSkip(live.internet) ? test.skip : test
10
+ const drive = isSkip(live.drive) ? test.skip : test
11
+
12
+ internet(`downloads and verifies a public file over HTTPS ${isSkip(live.internet) ? live.internet.reason : ''}`, async () => {
13
+ const ranged = await fileInspector.probe(httpClient.source('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'))
14
+ expect(ranged).toMatchObject({ status: 'match', detected: { kind: FileKind.Pdf }, probe: { randomAccess: true } })
15
+ const headOnly = await fileInspector.probe(httpClient.source('https://www.rfc-editor.org/rfc/rfc9110.pdf'))
16
+ expect(headOnly.detected?.kind).toBe(FileKind.Pdf)
17
+ expect(headOnly.probe.bytesRead).toBeLessThanOrEqual(1024 * 1024)
18
+ }, 60_000)
19
+
20
+ drive(`passes Google Drive's interstitial for a public file ${isSkip(live.drive) ? live.drive.reason : ''}`, async () => {
21
+ const response = await createHttpClient().request(process.env.FILE_STREAMS_LIVE_DRIVE_URL as string)
22
+ const head = await streamUtils.peek(response.body, 4096)
23
+ streamUtils.discard(head.stream)
24
+ const verdict = await fileInspector.inspect(head.head, { name: response.info.name, mime: response.info.mime })
25
+ expect(verdict.detected?.kind).not.toBe(FileKind.Html)
26
+ }, 120_000)
27
+ })