@milaboratories/pl-drivers 1.11.59 → 1.11.60

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 (330) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/clients/constructors.cjs +28 -28
  3. package/dist/clients/constructors.cjs.map +1 -1
  4. package/dist/clients/constructors.d.ts +17 -13
  5. package/dist/clients/constructors.js +28 -26
  6. package/dist/clients/constructors.js.map +1 -1
  7. package/dist/clients/crc32c.cjs +8 -13
  8. package/dist/clients/crc32c.cjs.map +1 -1
  9. package/dist/clients/crc32c.js +8 -12
  10. package/dist/clients/crc32c.js.map +1 -1
  11. package/dist/clients/download.cjs +119 -160
  12. package/dist/clients/download.cjs.map +1 -1
  13. package/dist/clients/download.d.ts +45 -41
  14. package/dist/clients/download.js +115 -137
  15. package/dist/clients/download.js.map +1 -1
  16. package/dist/clients/logs.cjs +78 -82
  17. package/dist/clients/logs.cjs.map +1 -1
  18. package/dist/clients/logs.d.ts +34 -24
  19. package/dist/clients/logs.js +77 -80
  20. package/dist/clients/logs.js.map +1 -1
  21. package/dist/clients/ls_api.cjs +62 -68
  22. package/dist/clients/ls_api.cjs.map +1 -1
  23. package/dist/clients/ls_api.d.ts +15 -11
  24. package/dist/clients/ls_api.js +61 -66
  25. package/dist/clients/ls_api.js.map +1 -1
  26. package/dist/clients/progress.cjs +49 -59
  27. package/dist/clients/progress.cjs.map +1 -1
  28. package/dist/clients/progress.d.ts +27 -20
  29. package/dist/clients/progress.js +48 -57
  30. package/dist/clients/progress.js.map +1 -1
  31. package/dist/clients/upload.cjs +189 -250
  32. package/dist/clients/upload.cjs.map +1 -1
  33. package/dist/clients/upload.d.ts +44 -34
  34. package/dist/clients/upload.js +187 -229
  35. package/dist/clients/upload.js.map +1 -1
  36. package/dist/drivers/download_blob/blob_key.cjs +9 -26
  37. package/dist/drivers/download_blob/blob_key.cjs.map +1 -1
  38. package/dist/drivers/download_blob/blob_key.js +7 -5
  39. package/dist/drivers/download_blob/blob_key.js.map +1 -1
  40. package/dist/drivers/download_blob/download_blob.cjs +395 -478
  41. package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
  42. package/dist/drivers/download_blob/download_blob.d.ts +102 -100
  43. package/dist/drivers/download_blob/download_blob.js +388 -453
  44. package/dist/drivers/download_blob/download_blob.js.map +1 -1
  45. package/dist/drivers/download_blob/download_blob_task.cjs +128 -163
  46. package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -1
  47. package/dist/drivers/download_blob/download_blob_task.js +125 -141
  48. package/dist/drivers/download_blob/download_blob_task.js.map +1 -1
  49. package/dist/drivers/download_blob/sparse_cache/cache.cjs +166 -195
  50. package/dist/drivers/download_blob/sparse_cache/cache.cjs.map +1 -1
  51. package/dist/drivers/download_blob/sparse_cache/cache.js +164 -193
  52. package/dist/drivers/download_blob/sparse_cache/cache.js.map +1 -1
  53. package/dist/drivers/download_blob/sparse_cache/file.cjs +29 -50
  54. package/dist/drivers/download_blob/sparse_cache/file.cjs.map +1 -1
  55. package/dist/drivers/download_blob/sparse_cache/file.js +28 -29
  56. package/dist/drivers/download_blob/sparse_cache/file.js.map +1 -1
  57. package/dist/drivers/download_blob/sparse_cache/ranges.cjs +48 -76
  58. package/dist/drivers/download_blob/sparse_cache/ranges.cjs.map +1 -1
  59. package/dist/drivers/download_blob/sparse_cache/ranges.js +47 -54
  60. package/dist/drivers/download_blob/sparse_cache/ranges.js.map +1 -1
  61. package/dist/drivers/download_blob_url/driver.cjs +125 -165
  62. package/dist/drivers/download_blob_url/driver.cjs.map +1 -1
  63. package/dist/drivers/download_blob_url/driver.d.ts +45 -42
  64. package/dist/drivers/download_blob_url/driver.js +123 -144
  65. package/dist/drivers/download_blob_url/driver.js.map +1 -1
  66. package/dist/drivers/download_blob_url/driver_id.cjs +4 -4
  67. package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -1
  68. package/dist/drivers/download_blob_url/driver_id.js +4 -3
  69. package/dist/drivers/download_blob_url/driver_id.js.map +1 -1
  70. package/dist/drivers/download_blob_url/snapshot.cjs +7 -11
  71. package/dist/drivers/download_blob_url/snapshot.cjs.map +1 -1
  72. package/dist/drivers/download_blob_url/snapshot.d.ts +10 -5
  73. package/dist/drivers/download_blob_url/snapshot.js +5 -8
  74. package/dist/drivers/download_blob_url/snapshot.js.map +1 -1
  75. package/dist/drivers/download_blob_url/task.cjs +147 -194
  76. package/dist/drivers/download_blob_url/task.cjs.map +1 -1
  77. package/dist/drivers/download_blob_url/task.d.ts +55 -57
  78. package/dist/drivers/download_blob_url/task.js +140 -170
  79. package/dist/drivers/download_blob_url/task.js.map +1 -1
  80. package/dist/drivers/download_url/driver.cjs +109 -146
  81. package/dist/drivers/download_url/driver.cjs.map +1 -1
  82. package/dist/drivers/download_url/driver.d.ts +59 -57
  83. package/dist/drivers/download_url/driver.js +107 -125
  84. package/dist/drivers/download_url/driver.js.map +1 -1
  85. package/dist/drivers/download_url/task.cjs +104 -137
  86. package/dist/drivers/download_url/task.cjs.map +1 -1
  87. package/dist/drivers/download_url/task.d.ts +33 -37
  88. package/dist/drivers/download_url/task.js +99 -113
  89. package/dist/drivers/download_url/task.js.map +1 -1
  90. package/dist/drivers/helpers/download_local_handle.cjs +13 -14
  91. package/dist/drivers/helpers/download_local_handle.cjs.map +1 -1
  92. package/dist/drivers/helpers/download_local_handle.js +13 -13
  93. package/dist/drivers/helpers/download_local_handle.js.map +1 -1
  94. package/dist/drivers/helpers/download_remote_handle.cjs +23 -24
  95. package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -1
  96. package/dist/drivers/helpers/download_remote_handle.js +22 -22
  97. package/dist/drivers/helpers/download_remote_handle.js.map +1 -1
  98. package/dist/drivers/helpers/files_cache.cjs +53 -64
  99. package/dist/drivers/helpers/files_cache.cjs.map +1 -1
  100. package/dist/drivers/helpers/files_cache.js +52 -62
  101. package/dist/drivers/helpers/files_cache.js.map +1 -1
  102. package/dist/drivers/helpers/helpers.cjs +24 -28
  103. package/dist/drivers/helpers/helpers.cjs.map +1 -1
  104. package/dist/drivers/helpers/helpers.d.ts +10 -7
  105. package/dist/drivers/helpers/helpers.js +24 -27
  106. package/dist/drivers/helpers/helpers.js.map +1 -1
  107. package/dist/drivers/helpers/logs_handle.cjs +24 -33
  108. package/dist/drivers/helpers/logs_handle.cjs.map +1 -1
  109. package/dist/drivers/helpers/logs_handle.js +24 -29
  110. package/dist/drivers/helpers/logs_handle.js.map +1 -1
  111. package/dist/drivers/helpers/ls_remote_import_handle.cjs +20 -20
  112. package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -1
  113. package/dist/drivers/helpers/ls_remote_import_handle.js +20 -18
  114. package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -1
  115. package/dist/drivers/helpers/ls_storage_entry.cjs +36 -40
  116. package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -1
  117. package/dist/drivers/helpers/ls_storage_entry.js +36 -37
  118. package/dist/drivers/helpers/ls_storage_entry.js.map +1 -1
  119. package/dist/drivers/helpers/polling_ops.d.ts +6 -5
  120. package/dist/drivers/helpers/read_file.cjs +34 -57
  121. package/dist/drivers/helpers/read_file.cjs.map +1 -1
  122. package/dist/drivers/helpers/read_file.js +30 -34
  123. package/dist/drivers/helpers/read_file.js.map +1 -1
  124. package/dist/drivers/logs.cjs +94 -112
  125. package/dist/drivers/logs.cjs.map +1 -1
  126. package/dist/drivers/logs.d.ts +35 -32
  127. package/dist/drivers/logs.js +93 -110
  128. package/dist/drivers/logs.js.map +1 -1
  129. package/dist/drivers/logs_stream.cjs +210 -242
  130. package/dist/drivers/logs_stream.cjs.map +1 -1
  131. package/dist/drivers/logs_stream.d.ts +55 -53
  132. package/dist/drivers/logs_stream.js +209 -240
  133. package/dist/drivers/logs_stream.js.map +1 -1
  134. package/dist/drivers/ls.cjs +151 -238
  135. package/dist/drivers/ls.cjs.map +1 -1
  136. package/dist/drivers/ls.d.ts +53 -49
  137. package/dist/drivers/ls.js +148 -216
  138. package/dist/drivers/ls.js.map +1 -1
  139. package/dist/drivers/types.cjs +25 -53
  140. package/dist/drivers/types.cjs.map +1 -1
  141. package/dist/drivers/types.d.ts +91 -106
  142. package/dist/drivers/types.js +23 -50
  143. package/dist/drivers/types.js.map +1 -1
  144. package/dist/drivers/upload.cjs +127 -153
  145. package/dist/drivers/upload.cjs.map +1 -1
  146. package/dist/drivers/upload.d.ts +52 -50
  147. package/dist/drivers/upload.js +126 -151
  148. package/dist/drivers/upload.js.map +1 -1
  149. package/dist/drivers/upload_task.cjs +223 -260
  150. package/dist/drivers/upload_task.cjs.map +1 -1
  151. package/dist/drivers/upload_task.d.ts +54 -52
  152. package/dist/drivers/upload_task.js +221 -258
  153. package/dist/drivers/upload_task.js.map +1 -1
  154. package/dist/drivers/urls/url.cjs +30 -35
  155. package/dist/drivers/urls/url.cjs.map +1 -1
  156. package/dist/drivers/urls/url.js +28 -33
  157. package/dist/drivers/urls/url.js.map +1 -1
  158. package/dist/drivers/virtual_storages.cjs +36 -48
  159. package/dist/drivers/virtual_storages.cjs.map +1 -1
  160. package/dist/drivers/virtual_storages.d.ts +6 -2
  161. package/dist/drivers/virtual_storages.js +32 -46
  162. package/dist/drivers/virtual_storages.js.map +1 -1
  163. package/dist/helpers/download.cjs +72 -95
  164. package/dist/helpers/download.cjs.map +1 -1
  165. package/dist/helpers/download.d.ts +13 -9
  166. package/dist/helpers/download.js +71 -93
  167. package/dist/helpers/download.js.map +1 -1
  168. package/dist/helpers/download_errors.cjs +28 -27
  169. package/dist/helpers/download_errors.cjs.map +1 -1
  170. package/dist/helpers/download_errors.d.ts +16 -13
  171. package/dist/helpers/download_errors.js +28 -26
  172. package/dist/helpers/download_errors.js.map +1 -1
  173. package/dist/helpers/validate.cjs +8 -7
  174. package/dist/helpers/validate.cjs.map +1 -1
  175. package/dist/helpers/validate.d.ts +4 -1
  176. package/dist/helpers/validate.js +6 -5
  177. package/dist/helpers/validate.js.map +1 -1
  178. package/dist/index.cjs +75 -79
  179. package/dist/index.d.ts +22 -22
  180. package/dist/index.js +22 -21
  181. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +238 -249
  182. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -1
  183. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +27 -27
  184. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -1
  185. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +25 -23
  186. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +26 -25
  187. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -1
  188. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +51 -87
  189. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +238 -245
  190. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -1
  191. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +295 -289
  192. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -1
  193. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +30 -30
  194. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -1
  195. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +29 -28
  196. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -1
  197. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +86 -150
  198. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +295 -285
  199. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -1
  200. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +385 -393
  201. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -1
  202. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +34 -34
  203. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -1
  204. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +33 -34
  205. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +33 -32
  206. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -1
  207. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +78 -129
  208. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +385 -387
  209. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -1
  210. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +570 -468
  211. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -1
  212. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +82 -82
  213. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -1
  214. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +109 -112
  215. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +81 -80
  216. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -1
  217. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +243 -264
  218. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +569 -460
  219. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -1
  220. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +751 -729
  221. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -1
  222. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +67 -67
  223. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -1
  224. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +66 -65
  225. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -1
  226. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +15 -381
  227. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +749 -718
  228. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -1
  229. package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
  230. package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
  231. package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
  232. package/dist/proto-grpc/google/protobuf/duration.js +91 -98
  233. package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
  234. package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
  235. package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
  236. package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
  237. package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
  238. package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
  239. package/dist/proto-rest/downloadapi.d.ts +85 -91
  240. package/dist/proto-rest/index.d.ts +11 -16
  241. package/dist/proto-rest/progressapi.d.ts +130 -140
  242. package/dist/proto-rest/streamingapi.d.ts +413 -434
  243. package/package.json +12 -12
  244. package/dist/clients/constructors.d.ts.map +0 -1
  245. package/dist/clients/crc32c.d.ts +0 -2
  246. package/dist/clients/crc32c.d.ts.map +0 -1
  247. package/dist/clients/download.d.ts.map +0 -1
  248. package/dist/clients/logs.d.ts.map +0 -1
  249. package/dist/clients/ls_api.d.ts.map +0 -1
  250. package/dist/clients/progress.d.ts.map +0 -1
  251. package/dist/clients/upload.d.ts.map +0 -1
  252. package/dist/drivers/download_blob/blob_key.d.ts +0 -5
  253. package/dist/drivers/download_blob/blob_key.d.ts.map +0 -1
  254. package/dist/drivers/download_blob/download_blob.d.ts.map +0 -1
  255. package/dist/drivers/download_blob/download_blob_task.d.ts +0 -56
  256. package/dist/drivers/download_blob/download_blob_task.d.ts.map +0 -1
  257. package/dist/drivers/download_blob/sparse_cache/cache.d.ts +0 -82
  258. package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +0 -1
  259. package/dist/drivers/download_blob/sparse_cache/file.d.ts +0 -8
  260. package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +0 -1
  261. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +0 -46
  262. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +0 -1
  263. package/dist/drivers/download_blob_url/driver.d.ts.map +0 -1
  264. package/dist/drivers/download_blob_url/driver_id.d.ts +0 -6
  265. package/dist/drivers/download_blob_url/driver_id.d.ts.map +0 -1
  266. package/dist/drivers/download_blob_url/snapshot.d.ts.map +0 -1
  267. package/dist/drivers/download_blob_url/task.d.ts.map +0 -1
  268. package/dist/drivers/download_url/driver.d.ts.map +0 -1
  269. package/dist/drivers/download_url/task.d.ts.map +0 -1
  270. package/dist/drivers/helpers/download_local_handle.d.ts +0 -11
  271. package/dist/drivers/helpers/download_local_handle.d.ts.map +0 -1
  272. package/dist/drivers/helpers/download_remote_handle.d.ts +0 -13
  273. package/dist/drivers/helpers/download_remote_handle.d.ts.map +0 -1
  274. package/dist/drivers/helpers/files_cache.d.ts +0 -29
  275. package/dist/drivers/helpers/files_cache.d.ts.map +0 -1
  276. package/dist/drivers/helpers/helpers.d.ts.map +0 -1
  277. package/dist/drivers/helpers/logs_handle.d.ts +0 -15
  278. package/dist/drivers/helpers/logs_handle.d.ts.map +0 -1
  279. package/dist/drivers/helpers/ls_remote_import_handle.d.ts +0 -8
  280. package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +0 -1
  281. package/dist/drivers/helpers/ls_storage_entry.d.ts +0 -23
  282. package/dist/drivers/helpers/ls_storage_entry.d.ts.map +0 -1
  283. package/dist/drivers/helpers/polling_ops.d.ts.map +0 -1
  284. package/dist/drivers/helpers/read_file.d.ts +0 -12
  285. package/dist/drivers/helpers/read_file.d.ts.map +0 -1
  286. package/dist/drivers/helpers/test_helpers.d.ts +0 -2
  287. package/dist/drivers/helpers/test_helpers.d.ts.map +0 -1
  288. package/dist/drivers/logs.d.ts.map +0 -1
  289. package/dist/drivers/logs_stream.d.ts.map +0 -1
  290. package/dist/drivers/ls.d.ts.map +0 -1
  291. package/dist/drivers/types.d.ts.map +0 -1
  292. package/dist/drivers/upload.d.ts.map +0 -1
  293. package/dist/drivers/upload_task.d.ts.map +0 -1
  294. package/dist/drivers/urls/url.d.ts +0 -13
  295. package/dist/drivers/urls/url.d.ts.map +0 -1
  296. package/dist/drivers/virtual_storages.d.ts.map +0 -1
  297. package/dist/helpers/download.d.ts.map +0 -1
  298. package/dist/helpers/download_errors.d.ts.map +0 -1
  299. package/dist/helpers/validate.d.ts.map +0 -1
  300. package/dist/index.cjs.map +0 -1
  301. package/dist/index.d.ts.map +0 -1
  302. package/dist/index.js.map +0 -1
  303. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
  304. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
  305. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -46
  306. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
  307. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
  308. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
  309. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
  310. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
  311. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
  312. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +0 -108
  313. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
  314. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
  315. package/dist/proto-grpc/google/api/http.d.ts +0 -460
  316. package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
  317. package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
  318. package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
  319. package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
  320. package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
  321. package/dist/proto-rest/downloadapi.d.ts.map +0 -1
  322. package/dist/proto-rest/index.d.ts.map +0 -1
  323. package/dist/proto-rest/lsapi.d.ts +0 -148
  324. package/dist/proto-rest/lsapi.d.ts.map +0 -1
  325. package/dist/proto-rest/progressapi.d.ts.map +0 -1
  326. package/dist/proto-rest/streamingapi.d.ts.map +0 -1
  327. package/dist/proto-rest/uploadapi.d.ts +0 -355
  328. package/dist/proto-rest/uploadapi.d.ts.map +0 -1
  329. package/dist/test_env.d.ts +0 -6
  330. package/dist/test_env.d.ts.map +0 -1
@@ -1,203 +1,174 @@
1
- import { ensureDirExists, fileExists, mapEntries } from '@milaboratories/ts-helpers';
2
- import { promises } from 'node:fs';
3
- import path__default from 'node:path';
4
- import { rangesFileName, readRangesFile, writeRangesFile, rangesSize, doesRangeExist, addRange } from './ranges.js';
5
- import { writeToSparseFile } from './file.js';
6
- import { functions } from '@milaboratories/helpers';
1
+ import { addRange, doesRangeExist, rangesFileName, rangesSize, readRangesFile, writeRangesFile } from "./ranges.js";
2
+ import { writeToSparseFile } from "./file.js";
3
+ import { ensureDirExists, fileExists, mapEntries } from "@milaboratories/ts-helpers";
4
+ import { functions } from "@milaboratories/helpers";
5
+ import { promises } from "node:fs";
6
+ import path from "node:path";
7
7
 
8
+ //#region src/drivers/download_blob/sparse_cache/cache.ts
8
9
  /** The implementer of SparseCacheRanges could throw it if ranges were corrupted. */
9
- class CorruptedRangesError extends Error {
10
- name = "CorruptedRangesError";
11
- }
10
+ var CorruptedRangesError = class extends Error {
11
+ name = "CorruptedRangesError";
12
+ };
12
13
  /** Stores ranges in a directory as JSON files (the default implementation). */
13
- class SparseCacheFsRanges {
14
- logger;
15
- cacheDir;
16
- constructor(logger, cacheDir) {
17
- this.logger = logger;
18
- this.cacheDir = cacheDir;
19
- }
20
- fPath(key) {
21
- return path__default.join(this.cacheDir, rangesFileName(key));
22
- }
23
- async get(key) {
24
- return await readRangesFile(this.logger, this.fPath(key));
25
- }
26
- async set(key, ranges) {
27
- return await writeRangesFile(this.logger, this.fPath(key), ranges);
28
- }
29
- async delete(key) {
30
- await promises.rm(this.fPath(key));
31
- }
32
- }
14
+ var SparseCacheFsRanges = class {
15
+ constructor(logger, cacheDir) {
16
+ this.logger = logger;
17
+ this.cacheDir = cacheDir;
18
+ }
19
+ fPath(key) {
20
+ return path.join(this.cacheDir, rangesFileName(key));
21
+ }
22
+ async get(key) {
23
+ return await readRangesFile(this.logger, this.fPath(key));
24
+ }
25
+ async set(key, ranges) {
26
+ return await writeRangesFile(this.logger, this.fPath(key), ranges);
27
+ }
28
+ async delete(key) {
29
+ await promises.rm(this.fPath(key));
30
+ }
31
+ };
33
32
  /** Stores sparse files in a directory (the default implementation). */
34
- class SparseCacheFsFile {
35
- logger;
36
- cacheDir;
37
- suffix = ".sparse.bin";
38
- constructor(logger, cacheDir) {
39
- this.logger = logger;
40
- this.cacheDir = cacheDir;
41
- }
42
- async all() {
43
- await ensureDirExists(this.cacheDir);
44
- const files = await promises.readdir(this.cacheDir);
45
- return files.filter((f) => f.endsWith(this.suffix));
46
- }
47
- async exists(key) {
48
- return await fileExists(this.path(key));
49
- }
50
- path(key) {
51
- return path__default.join(this.cacheDir, key + this.suffix);
52
- }
53
- async write(key, data, from) {
54
- await ensureDirExists(this.cacheDir);
55
- await writeToSparseFile(this.logger, process.platform, this.path(key), data, from);
56
- }
57
- async delete(key) {
58
- await promises.rm(this.path(key));
59
- }
60
- }
33
+ var SparseCacheFsFile = class {
34
+ suffix = ".sparse.bin";
35
+ constructor(logger, cacheDir) {
36
+ this.logger = logger;
37
+ this.cacheDir = cacheDir;
38
+ }
39
+ async all() {
40
+ await ensureDirExists(this.cacheDir);
41
+ return (await promises.readdir(this.cacheDir)).filter((f) => f.endsWith(this.suffix));
42
+ }
43
+ async exists(key) {
44
+ return await fileExists(this.path(key));
45
+ }
46
+ path(key) {
47
+ return path.join(this.cacheDir, key + this.suffix);
48
+ }
49
+ async write(key, data, from) {
50
+ await ensureDirExists(this.cacheDir);
51
+ await writeToSparseFile(this.logger, process.platform, this.path(key), data, from);
52
+ }
53
+ async delete(key) {
54
+ await promises.rm(this.path(key));
55
+ }
56
+ };
61
57
  /** LRU cache for ranges of sparse files. */
62
- class SparseCache {
63
- logger;
64
- maxSize;
65
- ranges;
66
- storage;
67
- /** Fields are public for tests. */
68
- /** The lock to make sure cache requests are done one by one. */
69
- lock = new functions.AwaitLock();
70
- keyToLastAccessTime = new Map();
71
- size = 0;
72
- constructor(logger,
73
- /** The hard limit in bytes. */
74
- maxSize, ranges, storage) {
75
- this.logger = logger;
76
- this.maxSize = maxSize;
77
- this.ranges = ranges;
78
- this.storage = storage;
79
- }
80
- /** Resets a cache's size by rereading everything we already store.
81
- * Safe for concurrent use. */
82
- async reset() {
83
- await withLock(this.lock, async () => {
84
- await this.resetUnsafe();
85
- });
86
- }
87
- /** Returns a path to the key if the range exists in a cache, otherwise returns undefined.
88
- * Safe for concurrent use. */
89
- async get(key, range) {
90
- return await withLock(this.lock, async () => {
91
- return await this.getUnsafe(key, range);
92
- });
93
- }
94
- /** Sets data to the cache's file and clear the cache if it's needed.
95
- * Safe for concurrent use. */
96
- async set(key, range, data) {
97
- await withLock(this.lock, async () => {
98
- await this.setUnsafe(key, range, data);
99
- });
100
- }
101
- async resetUnsafe() {
102
- this.size = 0;
103
- this.keyToLastAccessTime = new Map();
104
- const now = new Date();
105
- // In rmKey method we first deletes the key from a storage and only then from ranges,
106
- // so if something goes wrong between 2 operations,
107
- // on reset the logic will be correct.
108
- for (const key of await this.storage.all()) {
109
- const ranges = await this.ranges.get(key);
110
- this.size += rangesSize(ranges);
111
- this.keyToLastAccessTime.set(key, now);
112
- }
113
- }
114
- async getUnsafe(key, range) {
115
- // It first checks the storage, and then the ranges.
116
- // In another method, when we remove a key, it first deletes a key from a storage and then from ranges,
117
- // so if we don't have a key in storage but have it in ranges, the logic here is correct.
118
- // We probably could reverse the operations here and there, and everywhere we work with both storage and ranges.
119
- if (await this.storage.exists(key)) {
120
- this.keyToLastAccessTime.set(key, new Date());
121
- const ranges = await this.getRanges(key);
122
- if (doesRangeExist(ranges, range)) {
123
- return this.storage.path(key);
124
- }
125
- return undefined;
126
- }
127
- return undefined;
128
- }
129
- async setUnsafe(key, range, data) {
130
- await this.setWithoutEviction(key, range, data);
131
- await this.ensureEvicted();
132
- }
133
- /** Sets a key and recalculates a size, but doesn't ensures that the size is less than the hard limit. */
134
- async setWithoutEviction(key, range, data) {
135
- if (range.to - range.from !== data.length) {
136
- throw new Error(`SparseCache.set: trying to set ${key} with wrong range length: ` +
137
- `range: ${JSON.stringify(range)}, data: ${data.length}`);
138
- }
139
- this.keyToLastAccessTime.set(key, new Date());
140
- const ranges = await this.getRanges(key);
141
- this.size -= rangesSize(ranges);
142
- await this.storage.write(key, data, range.from);
143
- const newRanges = addRange(ranges, range);
144
- this.size += rangesSize(newRanges);
145
- await this.ranges.set(key, newRanges);
146
- }
147
- /** Ensures the size is less than hard limit by deleting the oldest keys. */
148
- async ensureEvicted() {
149
- const byTime = mapEntries(this.keyToLastAccessTime);
150
- byTime.sort(([_, aDate], [__, bDate]) => bDate.getTime() - aDate.getTime());
151
- while (this.size > this.maxSize) {
152
- const keyAndDate = byTime.pop(); // removes the oldest
153
- if (!keyAndDate) {
154
- break;
155
- }
156
- const [key, _] = keyAndDate;
157
- const ranges = await this.getRanges(key);
158
- this.size -= rangesSize(ranges);
159
- this.rmKey(key);
160
- }
161
- }
162
- /** Gets ranges and if they were corrupted, then remove the file from the cache and reset the cache's size. */
163
- async getRanges(key) {
164
- try {
165
- return await this.ranges.get(key);
166
- }
167
- catch (e) {
168
- if (e instanceof CorruptedRangesError) {
169
- // We need to reset a state of the cache and update current size,
170
- // it's the only way to calculate the real size when one of the ranges were corrupted.
171
- await this.rmKey(key);
172
- await this.resetUnsafe();
173
- return await this.ranges.get(key);
174
- }
175
- throw e;
176
- }
177
- }
178
- /** Removes a key the state of the cache. The size should be updated. */
179
- async rmKey(key) {
180
- await this.storage.delete(key);
181
- await this.ranges.delete(key);
182
- this.keyToLastAccessTime.delete(key);
183
- }
184
- async dispose() {
185
- await this.lock.acquireAsync();
186
- }
187
- async [Symbol.asyncDispose]() {
188
- await this.dispose();
189
- }
190
- }
58
+ var SparseCache = class {
59
+ /** Fields are public for tests. */
60
+ /** The lock to make sure cache requests are done one by one. */
61
+ lock = new functions.AwaitLock();
62
+ keyToLastAccessTime = /* @__PURE__ */ new Map();
63
+ size = 0;
64
+ constructor(logger, maxSize, ranges, storage) {
65
+ this.logger = logger;
66
+ this.maxSize = maxSize;
67
+ this.ranges = ranges;
68
+ this.storage = storage;
69
+ }
70
+ /** Resets a cache's size by rereading everything we already store.
71
+ * Safe for concurrent use. */
72
+ async reset() {
73
+ await withLock(this.lock, async () => {
74
+ await this.resetUnsafe();
75
+ });
76
+ }
77
+ /** Returns a path to the key if the range exists in a cache, otherwise returns undefined.
78
+ * Safe for concurrent use. */
79
+ async get(key, range) {
80
+ return await withLock(this.lock, async () => {
81
+ return await this.getUnsafe(key, range);
82
+ });
83
+ }
84
+ /** Sets data to the cache's file and clear the cache if it's needed.
85
+ * Safe for concurrent use. */
86
+ async set(key, range, data) {
87
+ await withLock(this.lock, async () => {
88
+ await this.setUnsafe(key, range, data);
89
+ });
90
+ }
91
+ async resetUnsafe() {
92
+ this.size = 0;
93
+ this.keyToLastAccessTime = /* @__PURE__ */ new Map();
94
+ const now = /* @__PURE__ */ new Date();
95
+ for (const key of await this.storage.all()) {
96
+ const ranges = await this.ranges.get(key);
97
+ this.size += rangesSize(ranges);
98
+ this.keyToLastAccessTime.set(key, now);
99
+ }
100
+ }
101
+ async getUnsafe(key, range) {
102
+ if (await this.storage.exists(key)) {
103
+ this.keyToLastAccessTime.set(key, /* @__PURE__ */ new Date());
104
+ if (doesRangeExist(await this.getRanges(key), range)) return this.storage.path(key);
105
+ return;
106
+ }
107
+ }
108
+ async setUnsafe(key, range, data) {
109
+ await this.setWithoutEviction(key, range, data);
110
+ await this.ensureEvicted();
111
+ }
112
+ /** Sets a key and recalculates a size, but doesn't ensures that the size is less than the hard limit. */
113
+ async setWithoutEviction(key, range, data) {
114
+ if (range.to - range.from !== data.length) throw new Error(`SparseCache.set: trying to set ${key} with wrong range length: range: ${JSON.stringify(range)}, data: ${data.length}`);
115
+ this.keyToLastAccessTime.set(key, /* @__PURE__ */ new Date());
116
+ const ranges = await this.getRanges(key);
117
+ this.size -= rangesSize(ranges);
118
+ await this.storage.write(key, data, range.from);
119
+ const newRanges = addRange(ranges, range);
120
+ this.size += rangesSize(newRanges);
121
+ await this.ranges.set(key, newRanges);
122
+ }
123
+ /** Ensures the size is less than hard limit by deleting the oldest keys. */
124
+ async ensureEvicted() {
125
+ const byTime = mapEntries(this.keyToLastAccessTime);
126
+ byTime.sort(([_, aDate], [__, bDate]) => bDate.getTime() - aDate.getTime());
127
+ while (this.size > this.maxSize) {
128
+ const keyAndDate = byTime.pop();
129
+ if (!keyAndDate) break;
130
+ const [key, _] = keyAndDate;
131
+ const ranges = await this.getRanges(key);
132
+ this.size -= rangesSize(ranges);
133
+ this.rmKey(key);
134
+ }
135
+ }
136
+ /** Gets ranges and if they were corrupted, then remove the file from the cache and reset the cache's size. */
137
+ async getRanges(key) {
138
+ try {
139
+ return await this.ranges.get(key);
140
+ } catch (e) {
141
+ if (e instanceof CorruptedRangesError) {
142
+ await this.rmKey(key);
143
+ await this.resetUnsafe();
144
+ return await this.ranges.get(key);
145
+ }
146
+ throw e;
147
+ }
148
+ }
149
+ /** Removes a key the state of the cache. The size should be updated. */
150
+ async rmKey(key) {
151
+ await this.storage.delete(key);
152
+ await this.ranges.delete(key);
153
+ this.keyToLastAccessTime.delete(key);
154
+ }
155
+ async dispose() {
156
+ await this.lock.acquireAsync();
157
+ }
158
+ async [Symbol.asyncDispose]() {
159
+ await this.dispose();
160
+ }
161
+ };
191
162
  /** Acquires the lock and executes a callback. */
192
163
  async function withLock(lock, cb) {
193
- try {
194
- await lock.acquireAsync();
195
- return await cb();
196
- }
197
- finally {
198
- lock.release();
199
- }
164
+ try {
165
+ await lock.acquireAsync();
166
+ return await cb();
167
+ } finally {
168
+ lock.release();
169
+ }
200
170
  }
201
171
 
172
+ //#endregion
202
173
  export { CorruptedRangesError, SparseCache, SparseCacheFsFile, SparseCacheFsRanges };
203
- //# sourceMappingURL=cache.js.map
174
+ //# sourceMappingURL=cache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sources":["../../../../src/drivers/download_blob/sparse_cache/cache.ts"],"sourcesContent":["import { RangeBytes } from \"@milaboratories/pl-model-common\";\nimport { ensureDirExists, fileExists, mapEntries, MiLogger } from \"@milaboratories/ts-helpers\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport {\n addRange,\n doesRangeExist,\n Ranges,\n rangesFileName,\n rangesSize,\n readRangesFile,\n writeRangesFile,\n} from \"./ranges\";\nimport { writeToSparseFile } from \"./file\";\nimport { functions } from \"@milaboratories/helpers\";\n\n/** The implementer of SparseCacheRanges could throw it if ranges were corrupted. */\nexport class CorruptedRangesError extends Error {\n name = \"CorruptedRangesError\";\n}\n\n/** Extracted ranges methods to be able to store ranges somewhere else (e.g. in memory for tests). */\nexport interface SparseCacheRanges {\n get(key: string): Promise<Ranges>;\n set(key: string, ranges: Ranges): Promise<void>;\n delete(key: string): Promise<void>;\n}\n\n/** Stores ranges in a directory as JSON files (the default implementation). */\nexport class SparseCacheFsRanges implements SparseCacheRanges {\n constructor(\n private readonly logger: MiLogger,\n private readonly cacheDir: string,\n ) {}\n\n private fPath(key: string): string {\n return path.join(this.cacheDir, rangesFileName(key));\n }\n\n async get(key: string): Promise<Ranges> {\n return await readRangesFile(this.logger, this.fPath(key));\n }\n\n async set(key: string, ranges: Ranges) {\n return await writeRangesFile(this.logger, this.fPath(key), ranges);\n }\n\n async delete(key: string) {\n await fs.rm(this.fPath(key));\n }\n}\n\n/** Extracted interface for storing sparse files. */\nexport interface SparseFileStorage {\n all(): Promise<string[]>;\n exists(key: string): Promise<boolean>;\n path(key: string): string;\n write(key: string, data: Uint8Array, from: number): Promise<void>;\n delete(key: string): Promise<void>;\n}\n\n/** Stores sparse files in a directory (the default implementation). */\nexport class SparseCacheFsFile implements SparseFileStorage {\n private readonly suffix = \".sparse.bin\";\n\n constructor(\n private readonly logger: MiLogger,\n private readonly cacheDir: string,\n ) {}\n\n async all(): Promise<string[]> {\n await ensureDirExists(this.cacheDir);\n const files = await fs.readdir(this.cacheDir);\n return files.filter((f) => f.endsWith(this.suffix));\n }\n\n async exists(key: string): Promise<boolean> {\n return await fileExists(this.path(key));\n }\n\n path(key: string): string {\n return path.join(this.cacheDir, key + this.suffix);\n }\n\n async write(key: string, data: Uint8Array, from: number): Promise<void> {\n await ensureDirExists(this.cacheDir);\n await writeToSparseFile(this.logger, process.platform, this.path(key), data, from);\n }\n\n async delete(key: string): Promise<void> {\n await fs.rm(this.path(key));\n }\n}\n\n/** LRU cache for ranges of sparse files. */\nexport class SparseCache implements AsyncDisposable {\n /** Fields are public for tests. */\n\n /** The lock to make sure cache requests are done one by one. */\n private lock = new functions.AwaitLock();\n\n public keyToLastAccessTime = new Map<string, Date>();\n public size = 0;\n\n constructor(\n public readonly logger: MiLogger,\n /** The hard limit in bytes. */\n public readonly maxSize: number,\n public readonly ranges: SparseCacheRanges,\n public readonly storage: SparseFileStorage,\n ) {}\n\n /** Resets a cache's size by rereading everything we already store.\n * Safe for concurrent use. */\n async reset() {\n await withLock(this.lock, async () => {\n await this.resetUnsafe();\n });\n }\n\n /** Returns a path to the key if the range exists in a cache, otherwise returns undefined.\n * Safe for concurrent use. */\n async get(key: string, range: RangeBytes): Promise<string | undefined> {\n return await withLock(this.lock, async () => {\n return await this.getUnsafe(key, range);\n });\n }\n\n /** Sets data to the cache's file and clear the cache if it's needed.\n * Safe for concurrent use. */\n async set(key: string, range: RangeBytes, data: Uint8Array): Promise<void> {\n await withLock(this.lock, async () => {\n await this.setUnsafe(key, range, data);\n });\n }\n\n private async resetUnsafe() {\n this.size = 0;\n this.keyToLastAccessTime = new Map<string, Date>();\n\n const now = new Date();\n // In rmKey method we first deletes the key from a storage and only then from ranges,\n // so if something goes wrong between 2 operations,\n // on reset the logic will be correct.\n for (const key of await this.storage.all()) {\n const ranges = await this.ranges.get(key);\n this.size += rangesSize(ranges);\n this.keyToLastAccessTime.set(key, now);\n }\n }\n\n private async getUnsafe(key: string, range: RangeBytes): Promise<string | undefined> {\n // It first checks the storage, and then the ranges.\n // In another method, when we remove a key, it first deletes a key from a storage and then from ranges,\n // so if we don't have a key in storage but have it in ranges, the logic here is correct.\n // We probably could reverse the operations here and there, and everywhere we work with both storage and ranges.\n if (await this.storage.exists(key)) {\n this.keyToLastAccessTime.set(key, new Date());\n\n const ranges = await this.getRanges(key);\n if (doesRangeExist(ranges, range)) {\n return this.storage.path(key);\n }\n\n return undefined;\n }\n\n return undefined;\n }\n\n private async setUnsafe(key: string, range: { from: number; to: number }, data: Uint8Array) {\n await this.setWithoutEviction(key, range, data);\n await this.ensureEvicted();\n }\n\n /** Sets a key and recalculates a size, but doesn't ensures that the size is less than the hard limit. */\n async setWithoutEviction(key: string, range: RangeBytes, data: Uint8Array): Promise<void> {\n if (range.to - range.from !== data.length) {\n throw new Error(\n `SparseCache.set: trying to set ${key} with wrong range length: ` +\n `range: ${JSON.stringify(range)}, data: ${data.length}`,\n );\n }\n\n this.keyToLastAccessTime.set(key, new Date());\n\n const ranges = await this.getRanges(key);\n this.size -= rangesSize(ranges);\n\n await this.storage.write(key, data, range.from);\n\n const newRanges = addRange(ranges, range);\n this.size += rangesSize(newRanges);\n\n await this.ranges.set(key, newRanges);\n }\n\n /** Ensures the size is less than hard limit by deleting the oldest keys. */\n async ensureEvicted(): Promise<void> {\n const byTime = mapEntries(this.keyToLastAccessTime);\n byTime.sort(([_, aDate], [__, bDate]) => bDate.getTime() - aDate.getTime());\n\n while (this.size > this.maxSize) {\n const keyAndDate = byTime.pop(); // removes the oldest\n if (!keyAndDate) {\n break;\n }\n const [key, _] = keyAndDate;\n\n const ranges = await this.getRanges(key);\n this.size -= rangesSize(ranges);\n this.rmKey(key);\n }\n }\n\n /** Gets ranges and if they were corrupted, then remove the file from the cache and reset the cache's size. */\n private async getRanges(key: string) {\n try {\n return await this.ranges.get(key);\n } catch (e: unknown) {\n if (e instanceof CorruptedRangesError) {\n // We need to reset a state of the cache and update current size,\n // it's the only way to calculate the real size when one of the ranges were corrupted.\n await this.rmKey(key);\n await this.resetUnsafe();\n\n return await this.ranges.get(key);\n }\n\n throw e;\n }\n }\n\n /** Removes a key the state of the cache. The size should be updated. */\n private async rmKey(key: string) {\n await this.storage.delete(key);\n await this.ranges.delete(key);\n this.keyToLastAccessTime.delete(key);\n }\n\n async dispose(): Promise<void> {\n await this.lock.acquireAsync();\n }\n\n async [Symbol.asyncDispose](): Promise<void> {\n await this.dispose();\n }\n}\n\n/** Acquires the lock and executes a callback. */\nasync function withLock<T>(lock: functions.AwaitLock, cb: () => Promise<T>): Promise<T> {\n try {\n await lock.acquireAsync();\n return await cb();\n } finally {\n lock.release();\n }\n}\n"],"names":["path","fs"],"mappings":";;;;;;;AAgBA;AACM,MAAO,oBAAqB,SAAQ,KAAK,CAAA;IAC7C,IAAI,GAAG,sBAAsB;AAC9B;AASD;MACa,mBAAmB,CAAA;AAEX,IAAA,MAAA;AACA,IAAA,QAAA;IAFnB,WAAA,CACmB,MAAgB,EAChB,QAAgB,EAAA;QADhB,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,QAAQ,GAAR,QAAQ;IACxB;AAEK,IAAA,KAAK,CAAC,GAAW,EAAA;AACvB,QAAA,OAAOA,aAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACtD;IAEA,MAAM,GAAG,CAAC,GAAW,EAAA;AACnB,QAAA,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;I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F,QAAA,MAAM,IAAI,CAAC,YAAY,EAAE;QACzB,OAAO,MAAM,EAAE,EAAE;IACnB;YAAU;QACR,IAAI,CAAC,OAAO,EAAE;IAChB;AACF;;;;"}
1
+ {"version":3,"file":"cache.js","names":["fs"],"sources":["../../../../src/drivers/download_blob/sparse_cache/cache.ts"],"sourcesContent":["import { RangeBytes } from \"@milaboratories/pl-model-common\";\nimport { ensureDirExists, fileExists, mapEntries, MiLogger } from \"@milaboratories/ts-helpers\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport {\n addRange,\n doesRangeExist,\n Ranges,\n rangesFileName,\n rangesSize,\n readRangesFile,\n writeRangesFile,\n} from \"./ranges\";\nimport { writeToSparseFile } from \"./file\";\nimport { functions } from \"@milaboratories/helpers\";\n\n/** The implementer of SparseCacheRanges could throw it if ranges were corrupted. */\nexport class CorruptedRangesError extends Error {\n name = \"CorruptedRangesError\";\n}\n\n/** Extracted ranges methods to be able to store ranges somewhere else (e.g. in memory for tests). */\nexport interface SparseCacheRanges {\n get(key: string): Promise<Ranges>;\n set(key: string, ranges: Ranges): Promise<void>;\n delete(key: string): Promise<void>;\n}\n\n/** Stores ranges in a directory as JSON files (the default implementation). */\nexport class SparseCacheFsRanges implements SparseCacheRanges {\n constructor(\n private readonly logger: MiLogger,\n private readonly cacheDir: string,\n ) {}\n\n private fPath(key: string): string {\n return path.join(this.cacheDir, rangesFileName(key));\n }\n\n async get(key: string): Promise<Ranges> {\n return await readRangesFile(this.logger, this.fPath(key));\n }\n\n async set(key: string, ranges: Ranges) {\n return await writeRangesFile(this.logger, this.fPath(key), ranges);\n }\n\n async delete(key: string) {\n await fs.rm(this.fPath(key));\n }\n}\n\n/** Extracted interface for storing sparse files. */\nexport interface SparseFileStorage {\n all(): Promise<string[]>;\n exists(key: string): Promise<boolean>;\n path(key: string): string;\n write(key: string, data: Uint8Array, from: number): Promise<void>;\n delete(key: string): Promise<void>;\n}\n\n/** Stores sparse files in a directory (the default implementation). */\nexport class SparseCacheFsFile implements SparseFileStorage {\n private readonly suffix = \".sparse.bin\";\n\n constructor(\n private readonly logger: MiLogger,\n private readonly cacheDir: string,\n ) {}\n\n async all(): Promise<string[]> {\n await ensureDirExists(this.cacheDir);\n const files = await fs.readdir(this.cacheDir);\n return files.filter((f) => f.endsWith(this.suffix));\n }\n\n async exists(key: string): Promise<boolean> {\n return await fileExists(this.path(key));\n }\n\n path(key: string): string {\n return path.join(this.cacheDir, key + this.suffix);\n }\n\n async write(key: string, data: Uint8Array, from: number): Promise<void> {\n await ensureDirExists(this.cacheDir);\n await writeToSparseFile(this.logger, process.platform, this.path(key), data, from);\n }\n\n async delete(key: string): Promise<void> {\n await fs.rm(this.path(key));\n }\n}\n\n/** LRU cache for ranges of sparse files. */\nexport class SparseCache implements AsyncDisposable {\n /** Fields are public for tests. */\n\n /** The lock to make sure cache requests are done one by one. */\n private lock = new functions.AwaitLock();\n\n public keyToLastAccessTime = new Map<string, Date>();\n public size = 0;\n\n constructor(\n public readonly logger: MiLogger,\n /** The hard limit in bytes. */\n public readonly maxSize: number,\n public readonly ranges: SparseCacheRanges,\n public readonly storage: SparseFileStorage,\n ) {}\n\n /** Resets a cache's size by rereading everything we already store.\n * Safe for concurrent use. */\n async reset() {\n await withLock(this.lock, async () => {\n await this.resetUnsafe();\n });\n }\n\n /** Returns a path to the key if the range exists in a cache, otherwise returns undefined.\n * Safe for concurrent use. */\n async get(key: string, range: RangeBytes): Promise<string | undefined> {\n return await withLock(this.lock, async () => {\n return await this.getUnsafe(key, range);\n });\n }\n\n /** Sets data to the cache's file and clear the cache if it's needed.\n * Safe for concurrent use. */\n async set(key: string, range: RangeBytes, data: Uint8Array): Promise<void> {\n await withLock(this.lock, async () => {\n await this.setUnsafe(key, range, data);\n });\n }\n\n private async resetUnsafe() {\n this.size = 0;\n this.keyToLastAccessTime = new Map<string, Date>();\n\n const now = new Date();\n // In rmKey method we first deletes the key from a storage and only then from ranges,\n // so if something goes wrong between 2 operations,\n // on reset the logic will be correct.\n for (const key of await this.storage.all()) {\n const ranges = await this.ranges.get(key);\n this.size += rangesSize(ranges);\n this.keyToLastAccessTime.set(key, now);\n }\n }\n\n private async getUnsafe(key: string, range: RangeBytes): Promise<string | undefined> {\n // It first checks the storage, and then the ranges.\n // In another method, when we remove a key, it first deletes a key from a storage and then from ranges,\n // so if we don't have a key in storage but have it in ranges, the logic here is correct.\n // We probably could reverse the operations here and there, and everywhere we work with both storage and ranges.\n if (await this.storage.exists(key)) {\n this.keyToLastAccessTime.set(key, new Date());\n\n const ranges = await this.getRanges(key);\n if (doesRangeExist(ranges, range)) {\n return this.storage.path(key);\n }\n\n return undefined;\n }\n\n return undefined;\n }\n\n private async setUnsafe(key: string, range: { from: number; to: number }, data: Uint8Array) {\n await this.setWithoutEviction(key, range, data);\n await this.ensureEvicted();\n }\n\n /** Sets a key and recalculates a size, but doesn't ensures that the size is less than the hard limit. */\n async setWithoutEviction(key: string, range: RangeBytes, data: Uint8Array): Promise<void> {\n if (range.to - range.from !== data.length) {\n throw new Error(\n `SparseCache.set: trying to set ${key} with wrong range length: ` +\n `range: ${JSON.stringify(range)}, data: ${data.length}`,\n );\n }\n\n this.keyToLastAccessTime.set(key, new Date());\n\n const ranges = await this.getRanges(key);\n this.size -= rangesSize(ranges);\n\n await this.storage.write(key, data, range.from);\n\n const newRanges = addRange(ranges, range);\n this.size += rangesSize(newRanges);\n\n await this.ranges.set(key, newRanges);\n }\n\n /** Ensures the size is less than hard limit by deleting the oldest keys. */\n async ensureEvicted(): Promise<void> {\n const byTime = mapEntries(this.keyToLastAccessTime);\n byTime.sort(([_, aDate], [__, bDate]) => bDate.getTime() - aDate.getTime());\n\n while (this.size > this.maxSize) {\n const keyAndDate = byTime.pop(); // removes the oldest\n if (!keyAndDate) {\n break;\n }\n const [key, _] = keyAndDate;\n\n const ranges = await this.getRanges(key);\n this.size -= rangesSize(ranges);\n this.rmKey(key);\n }\n }\n\n /** Gets ranges and if they were corrupted, then remove the file from the cache and reset the cache's size. */\n private async getRanges(key: string) {\n try {\n return await this.ranges.get(key);\n } catch (e: unknown) {\n if (e instanceof CorruptedRangesError) {\n // We need to reset a state of the cache and update current size,\n // it's the only way to calculate the real size when one of the ranges were corrupted.\n await this.rmKey(key);\n await this.resetUnsafe();\n\n return await this.ranges.get(key);\n }\n\n throw e;\n }\n }\n\n /** Removes a key the state of the cache. The size should be updated. */\n private async rmKey(key: string) {\n await this.storage.delete(key);\n await this.ranges.delete(key);\n this.keyToLastAccessTime.delete(key);\n }\n\n async dispose(): Promise<void> {\n await this.lock.acquireAsync();\n }\n\n async [Symbol.asyncDispose](): Promise<void> {\n await this.dispose();\n }\n}\n\n/** Acquires the lock and executes a callback. */\nasync function withLock<T>(lock: functions.AwaitLock, cb: () => Promise<T>): Promise<T> {\n try {\n await lock.acquireAsync();\n return await cb();\n } finally {\n lock.release();\n }\n}\n"],"mappings":";;;;;;;;;AAiBA,IAAa,uBAAb,cAA0C,MAAM;CAC9C,OAAO;;;AAWT,IAAa,sBAAb,MAA8D;CAC5D,YACE,AAAiB,QACjB,AAAiB,UACjB;EAFiB;EACA;;CAGnB,AAAQ,MAAM,KAAqB;AACjC,SAAO,KAAK,KAAK,KAAK,UAAU,eAAe,IAAI,CAAC;;CAGtD,MAAM,IAAI,KAA8B;AACtC,SAAO,MAAM,eAAe,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;;CAG3D,MAAM,IAAI,KAAa,QAAgB;AACrC,SAAO,MAAM,gBAAgB,KAAK,QAAQ,KAAK,MAAM,IAAI,EAAE,OAAO;;CAGpE,MAAM,OAAO,KAAa;AACxB,QAAMA,SAAG,GAAG,KAAK,MAAM,IAAI,CAAC;;;;AAchC,IAAa,oBAAb,MAA4D;CAC1D,AAAiB,SAAS;CAE1B,YACE,AAAiB,QACjB,AAAiB,UACjB;EAFiB;EACA;;CAGnB,MAAM,MAAyB;AAC7B,QAAM,gBAAgB,KAAK,SAAS;AAEpC,UADc,MAAMA,SAAG,QAAQ,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,MAAM,IAAI;;;;CAKnB,MAAc,UAAU,KAAa;AACnC,MAAI;AACF,UAAO,MAAM,KAAK,OAAO,IAAI,IAAI;WAC1B,GAAY;AACnB,OAAI,aAAa,sBAAsB;AAGrC,UAAM,KAAK,MAAM,IAAI;AACrB,UAAM,KAAK,aAAa;AAExB,WAAO,MAAM,KAAK,OAAO,IAAI,IAAI;;AAGnC,SAAM;;;;CAKV,MAAc,MAAM,KAAa;AAC/B,QAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,QAAM,KAAK,OAAO,OAAO,IAAI;AAC7B,OAAK,oBAAoB,OAAO,IAAI;;CAGtC,MAAM,UAAyB;AAC7B,QAAM,KAAK,KAAK,cAAc;;CAGhC,OAAO,OAAO,gBAA+B;AAC3C,QAAM,KAAK,SAAS;;;;AAKxB,eAAe,SAAY,MAA2B,IAAkC;AACtF,KAAI;AACF,QAAM,KAAK,cAAc;AACzB,SAAO,MAAM,IAAI;WACT;AACR,OAAK,SAAS"}
@@ -1,62 +1,41 @@
1
- 'use strict';
2
-
3
- var tsHelpers = require('@milaboratories/ts-helpers');
4
- var fsp = require('node:fs/promises');
5
-
6
- function _interopNamespaceDefault(e) {
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
1
+ const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
2
+ let node_fs_promises = require("node:fs/promises");
3
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
4
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
24
5
 
6
+ //#region src/drivers/download_blob/sparse_cache/file.ts
25
7
  /** Creates a sparse file for all systems
26
- * Table of what supports sparse files:
27
- * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */
8
+ * Table of what supports sparse files:
9
+ * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */
28
10
  async function createSparseFile(logger, path, platform) {
29
- try {
30
- const ensureCreated = await fsp__namespace.open(path, "w");
31
- await ensureCreated.close();
32
- await ensureSparseOnWindows(path, platform);
33
- }
34
- catch (error) {
35
- logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);
36
- }
11
+ try {
12
+ await (await node_fs_promises.open(path, "w")).close();
13
+ await ensureSparseOnWindows(path, platform);
14
+ } catch (error) {
15
+ logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);
16
+ }
37
17
  }
38
18
  /** Sets a sparse flag on Windows.
39
- * We could check the file is sparse by running:
40
- * `fsutil sparse queryflag <path>`
41
- * and
42
- * `fsutil sparse queryrange <path>`
43
- */
19
+ * We could check the file is sparse by running:
20
+ * `fsutil sparse queryflag <path>`
21
+ * and
22
+ * `fsutil sparse queryrange <path>`
23
+ */
44
24
  async function ensureSparseOnWindows(path, platform) {
45
- if (platform === "win32") {
46
- // https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-sparse
47
- await tsHelpers.spawnAsync("fsutil", ["sparse", "setflag", path], { stdio: "pipe" });
48
- }
25
+ if (platform === "win32") await (0, _milaboratories_ts_helpers.spawnAsync)("fsutil", [
26
+ "sparse",
27
+ "setflag",
28
+ path
29
+ ], { stdio: "pipe" });
49
30
  }
50
31
  /** Ensures the file is created and writes to it. */
51
32
  async function writeToSparseFile(logger, platform, path, data, from) {
52
- if (!(await tsHelpers.fileExists(path))) {
53
- await createSparseFile(logger, path, platform);
54
- }
55
- const fileHandle = await fsp__namespace.open(path, "r+");
56
- await fileHandle.write(data, 0, data.length, from);
57
- await fileHandle.close();
33
+ if (!await (0, _milaboratories_ts_helpers.fileExists)(path)) await createSparseFile(logger, path, platform);
34
+ const fileHandle = await node_fs_promises.open(path, "r+");
35
+ await fileHandle.write(data, 0, data.length, from);
36
+ await fileHandle.close();
58
37
  }
59
38
 
60
- exports.createSparseFile = createSparseFile;
39
+ //#endregion
61
40
  exports.writeToSparseFile = writeToSparseFile;
62
- //# sourceMappingURL=file.cjs.map
41
+ //# sourceMappingURL=file.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.cjs","sources":["../../../../src/drivers/download_blob/sparse_cache/file.ts"],"sourcesContent":["import { fileExists, MiLogger, spawnAsync } from \"@milaboratories/ts-helpers\";\nimport * as fs from \"node:fs/promises\";\n\n/** Creates a sparse file for all systems\n * Table of what supports sparse files:\n * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */\nexport async function createSparseFile(logger: MiLogger, path: string, platform: NodeJS.Platform) {\n try {\n const ensureCreated = await fs.open(path, \"w\");\n await ensureCreated.close();\n\n await ensureSparseOnWindows(path, platform);\n } catch (error: unknown) {\n logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);\n }\n}\n\n/** Sets a sparse flag on Windows.\n * We could check the file is sparse by running:\n * `fsutil sparse queryflag <path>`\n * and\n * `fsutil sparse queryrange <path>`\n */\nasync function ensureSparseOnWindows(path: string, platform: NodeJS.Platform) {\n if (platform === \"win32\") {\n // https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-sparse\n await spawnAsync(\"fsutil\", [\"sparse\", \"setflag\", path], { stdio: \"pipe\" });\n }\n}\n\n/** Ensures the file is created and writes to it. */\nexport async function writeToSparseFile(\n logger: MiLogger,\n platform: NodeJS.Platform,\n path: string,\n data: Uint8Array,\n from: number,\n) {\n if (!(await fileExists(path))) {\n await createSparseFile(logger, path, platform);\n }\n\n const fileHandle = await fs.open(path, \"r+\");\n await fileHandle.write(data, 0, data.length, from);\n await fileHandle.close();\n}\n"],"names":["fs","spawnAsync","fileExists"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAE6F;AACtF,eAAe,gBAAgB,CAAC,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spawnAsync } from \"@milaboratories/ts-helpers\";\nimport * as fs from \"node:fs/promises\";\n\n/** Creates a sparse file for all systems\n * Table of what supports sparse files:\n * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */\nexport async function createSparseFile(logger: MiLogger, path: string, platform: NodeJS.Platform) {\n try {\n const ensureCreated = await fs.open(path, \"w\");\n await ensureCreated.close();\n\n await ensureSparseOnWindows(path, platform);\n } catch (error: unknown) {\n logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);\n }\n}\n\n/** Sets a sparse flag on Windows.\n * We could check the file is sparse by running:\n * `fsutil sparse queryflag <path>`\n * and\n * `fsutil sparse queryrange <path>`\n */\nasync function ensureSparseOnWindows(path: string, platform: NodeJS.Platform) {\n if (platform === \"win32\") {\n // https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-sparse\n await spawnAsync(\"fsutil\", [\"sparse\", \"setflag\", path], { stdio: \"pipe\" });\n }\n}\n\n/** Ensures the file is created and writes to it. */\nexport async function writeToSparseFile(\n logger: MiLogger,\n platform: NodeJS.Platform,\n path: string,\n data: Uint8Array,\n from: number,\n) {\n if (!(await fileExists(path))) {\n await createSparseFile(logger, path, platform);\n }\n\n const fileHandle = await fs.open(path, \"r+\");\n await fileHandle.write(data, 0, data.length, from);\n await fileHandle.close();\n}\n"],"mappings":";;;;;;;;;AAMA,eAAsB,iBAAiB,QAAkB,MAAc,UAA2B;AAChG,KAAI;AAEF,SADsB,MAAMA,iBAAG,KAAK,MAAM,IAAI,EAC1B,OAAO;AAE3B,QAAM,sBAAsB,MAAM,SAAS;UACpC,OAAgB;AACvB,SAAO,MAAM,uBAAuB,KAAK,eAAe,SAAS,IAAI,QAAQ;;;;;;;;;AAUjF,eAAe,sBAAsB,MAAc,UAA2B;AAC5E,KAAI,aAAa,QAEf,kDAAiB,UAAU;EAAC;EAAU;EAAW;EAAK,EAAE,EAAE,OAAO,QAAQ,CAAC;;;AAK9E,eAAsB,kBACpB,QACA,UACA,MACA,MACA,MACA;AACA,KAAI,CAAE,iDAAiB,KAAK,CAC1B,OAAM,iBAAiB,QAAQ,MAAM,SAAS;CAGhD,MAAM,aAAa,MAAMA,iBAAG,KAAK,MAAM,KAAK;AAC5C,OAAM,WAAW,MAAM,MAAM,GAAG,KAAK,QAAQ,KAAK;AAClD,OAAM,WAAW,OAAO"}
@@ -1,40 +1,39 @@
1
- import { fileExists, spawnAsync } from '@milaboratories/ts-helpers';
2
- import * as fsp from 'node:fs/promises';
1
+ import * as fs from "node:fs/promises";
2
+ import { fileExists, spawnAsync } from "@milaboratories/ts-helpers";
3
3
 
4
+ //#region src/drivers/download_blob/sparse_cache/file.ts
4
5
  /** Creates a sparse file for all systems
5
- * Table of what supports sparse files:
6
- * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */
6
+ * Table of what supports sparse files:
7
+ * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */
7
8
  async function createSparseFile(logger, path, platform) {
8
- try {
9
- const ensureCreated = await fsp.open(path, "w");
10
- await ensureCreated.close();
11
- await ensureSparseOnWindows(path, platform);
12
- }
13
- catch (error) {
14
- logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);
15
- }
9
+ try {
10
+ await (await fs.open(path, "w")).close();
11
+ await ensureSparseOnWindows(path, platform);
12
+ } catch (error) {
13
+ logger.error(`Error creating file ${path} on platform ${platform}: ${error}`);
14
+ }
16
15
  }
17
16
  /** Sets a sparse flag on Windows.
18
- * We could check the file is sparse by running:
19
- * `fsutil sparse queryflag <path>`
20
- * and
21
- * `fsutil sparse queryrange <path>`
22
- */
17
+ * We could check the file is sparse by running:
18
+ * `fsutil sparse queryflag <path>`
19
+ * and
20
+ * `fsutil sparse queryrange <path>`
21
+ */
23
22
  async function ensureSparseOnWindows(path, platform) {
24
- if (platform === "win32") {
25
- // https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-sparse
26
- await spawnAsync("fsutil", ["sparse", "setflag", path], { stdio: "pipe" });
27
- }
23
+ if (platform === "win32") await spawnAsync("fsutil", [
24
+ "sparse",
25
+ "setflag",
26
+ path
27
+ ], { stdio: "pipe" });
28
28
  }
29
29
  /** Ensures the file is created and writes to it. */
30
30
  async function writeToSparseFile(logger, platform, path, data, from) {
31
- if (!(await fileExists(path))) {
32
- await createSparseFile(logger, path, platform);
33
- }
34
- const fileHandle = await fsp.open(path, "r+");
35
- await fileHandle.write(data, 0, data.length, from);
36
- await fileHandle.close();
31
+ if (!await fileExists(path)) await createSparseFile(logger, path, platform);
32
+ const fileHandle = await fs.open(path, "r+");
33
+ await fileHandle.write(data, 0, data.length, from);
34
+ await fileHandle.close();
37
35
  }
38
36
 
39
- export { createSparseFile, writeToSparseFile };
40
- //# sourceMappingURL=file.js.map
37
+ //#endregion
38
+ export { writeToSparseFile };
39
+ //# sourceMappingURL=file.js.map