@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.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/clients/constructors.cjs +28 -28
- package/dist/clients/constructors.cjs.map +1 -1
- package/dist/clients/constructors.d.ts +17 -13
- package/dist/clients/constructors.js +28 -26
- package/dist/clients/constructors.js.map +1 -1
- package/dist/clients/crc32c.cjs +8 -13
- package/dist/clients/crc32c.cjs.map +1 -1
- package/dist/clients/crc32c.js +8 -12
- package/dist/clients/crc32c.js.map +1 -1
- package/dist/clients/download.cjs +119 -160
- package/dist/clients/download.cjs.map +1 -1
- package/dist/clients/download.d.ts +45 -41
- package/dist/clients/download.js +115 -137
- package/dist/clients/download.js.map +1 -1
- package/dist/clients/logs.cjs +78 -82
- package/dist/clients/logs.cjs.map +1 -1
- package/dist/clients/logs.d.ts +34 -24
- package/dist/clients/logs.js +77 -80
- package/dist/clients/logs.js.map +1 -1
- package/dist/clients/ls_api.cjs +62 -68
- package/dist/clients/ls_api.cjs.map +1 -1
- package/dist/clients/ls_api.d.ts +15 -11
- package/dist/clients/ls_api.js +61 -66
- package/dist/clients/ls_api.js.map +1 -1
- package/dist/clients/progress.cjs +49 -59
- package/dist/clients/progress.cjs.map +1 -1
- package/dist/clients/progress.d.ts +27 -20
- package/dist/clients/progress.js +48 -57
- package/dist/clients/progress.js.map +1 -1
- package/dist/clients/upload.cjs +189 -250
- package/dist/clients/upload.cjs.map +1 -1
- package/dist/clients/upload.d.ts +44 -34
- package/dist/clients/upload.js +187 -229
- package/dist/clients/upload.js.map +1 -1
- package/dist/drivers/download_blob/blob_key.cjs +9 -26
- package/dist/drivers/download_blob/blob_key.cjs.map +1 -1
- package/dist/drivers/download_blob/blob_key.js +7 -5
- package/dist/drivers/download_blob/blob_key.js.map +1 -1
- package/dist/drivers/download_blob/download_blob.cjs +395 -478
- package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob.d.ts +102 -100
- package/dist/drivers/download_blob/download_blob.js +388 -453
- package/dist/drivers/download_blob/download_blob.js.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.cjs +128 -163
- package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.js +125 -141
- package/dist/drivers/download_blob/download_blob_task.js.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/cache.cjs +166 -195
- package/dist/drivers/download_blob/sparse_cache/cache.cjs.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/cache.js +164 -193
- package/dist/drivers/download_blob/sparse_cache/cache.js.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/file.cjs +29 -50
- package/dist/drivers/download_blob/sparse_cache/file.cjs.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/file.js +28 -29
- package/dist/drivers/download_blob/sparse_cache/file.js.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/ranges.cjs +48 -76
- package/dist/drivers/download_blob/sparse_cache/ranges.cjs.map +1 -1
- package/dist/drivers/download_blob/sparse_cache/ranges.js +47 -54
- package/dist/drivers/download_blob/sparse_cache/ranges.js.map +1 -1
- package/dist/drivers/download_blob_url/driver.cjs +125 -165
- package/dist/drivers/download_blob_url/driver.cjs.map +1 -1
- package/dist/drivers/download_blob_url/driver.d.ts +45 -42
- package/dist/drivers/download_blob_url/driver.js +123 -144
- package/dist/drivers/download_blob_url/driver.js.map +1 -1
- package/dist/drivers/download_blob_url/driver_id.cjs +4 -4
- package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -1
- package/dist/drivers/download_blob_url/driver_id.js +4 -3
- package/dist/drivers/download_blob_url/driver_id.js.map +1 -1
- package/dist/drivers/download_blob_url/snapshot.cjs +7 -11
- package/dist/drivers/download_blob_url/snapshot.cjs.map +1 -1
- package/dist/drivers/download_blob_url/snapshot.d.ts +10 -5
- package/dist/drivers/download_blob_url/snapshot.js +5 -8
- package/dist/drivers/download_blob_url/snapshot.js.map +1 -1
- package/dist/drivers/download_blob_url/task.cjs +147 -194
- package/dist/drivers/download_blob_url/task.cjs.map +1 -1
- package/dist/drivers/download_blob_url/task.d.ts +55 -57
- package/dist/drivers/download_blob_url/task.js +140 -170
- package/dist/drivers/download_blob_url/task.js.map +1 -1
- package/dist/drivers/download_url/driver.cjs +109 -146
- package/dist/drivers/download_url/driver.cjs.map +1 -1
- package/dist/drivers/download_url/driver.d.ts +59 -57
- package/dist/drivers/download_url/driver.js +107 -125
- package/dist/drivers/download_url/driver.js.map +1 -1
- package/dist/drivers/download_url/task.cjs +104 -137
- package/dist/drivers/download_url/task.cjs.map +1 -1
- package/dist/drivers/download_url/task.d.ts +33 -37
- package/dist/drivers/download_url/task.js +99 -113
- package/dist/drivers/download_url/task.js.map +1 -1
- package/dist/drivers/helpers/download_local_handle.cjs +13 -14
- package/dist/drivers/helpers/download_local_handle.cjs.map +1 -1
- package/dist/drivers/helpers/download_local_handle.js +13 -13
- package/dist/drivers/helpers/download_local_handle.js.map +1 -1
- package/dist/drivers/helpers/download_remote_handle.cjs +23 -24
- package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -1
- package/dist/drivers/helpers/download_remote_handle.js +22 -22
- package/dist/drivers/helpers/download_remote_handle.js.map +1 -1
- package/dist/drivers/helpers/files_cache.cjs +53 -64
- package/dist/drivers/helpers/files_cache.cjs.map +1 -1
- package/dist/drivers/helpers/files_cache.js +52 -62
- package/dist/drivers/helpers/files_cache.js.map +1 -1
- package/dist/drivers/helpers/helpers.cjs +24 -28
- package/dist/drivers/helpers/helpers.cjs.map +1 -1
- package/dist/drivers/helpers/helpers.d.ts +10 -7
- package/dist/drivers/helpers/helpers.js +24 -27
- package/dist/drivers/helpers/helpers.js.map +1 -1
- package/dist/drivers/helpers/logs_handle.cjs +24 -33
- package/dist/drivers/helpers/logs_handle.cjs.map +1 -1
- package/dist/drivers/helpers/logs_handle.js +24 -29
- package/dist/drivers/helpers/logs_handle.js.map +1 -1
- package/dist/drivers/helpers/ls_remote_import_handle.cjs +20 -20
- package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -1
- package/dist/drivers/helpers/ls_remote_import_handle.js +20 -18
- package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -1
- package/dist/drivers/helpers/ls_storage_entry.cjs +36 -40
- package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -1
- package/dist/drivers/helpers/ls_storage_entry.js +36 -37
- package/dist/drivers/helpers/ls_storage_entry.js.map +1 -1
- package/dist/drivers/helpers/polling_ops.d.ts +6 -5
- package/dist/drivers/helpers/read_file.cjs +34 -57
- package/dist/drivers/helpers/read_file.cjs.map +1 -1
- package/dist/drivers/helpers/read_file.js +30 -34
- package/dist/drivers/helpers/read_file.js.map +1 -1
- package/dist/drivers/logs.cjs +94 -112
- package/dist/drivers/logs.cjs.map +1 -1
- package/dist/drivers/logs.d.ts +35 -32
- package/dist/drivers/logs.js +93 -110
- package/dist/drivers/logs.js.map +1 -1
- package/dist/drivers/logs_stream.cjs +210 -242
- package/dist/drivers/logs_stream.cjs.map +1 -1
- package/dist/drivers/logs_stream.d.ts +55 -53
- package/dist/drivers/logs_stream.js +209 -240
- package/dist/drivers/logs_stream.js.map +1 -1
- package/dist/drivers/ls.cjs +151 -238
- package/dist/drivers/ls.cjs.map +1 -1
- package/dist/drivers/ls.d.ts +53 -49
- package/dist/drivers/ls.js +148 -216
- package/dist/drivers/ls.js.map +1 -1
- package/dist/drivers/types.cjs +25 -53
- package/dist/drivers/types.cjs.map +1 -1
- package/dist/drivers/types.d.ts +91 -106
- package/dist/drivers/types.js +23 -50
- package/dist/drivers/types.js.map +1 -1
- package/dist/drivers/upload.cjs +127 -153
- package/dist/drivers/upload.cjs.map +1 -1
- package/dist/drivers/upload.d.ts +52 -50
- package/dist/drivers/upload.js +126 -151
- package/dist/drivers/upload.js.map +1 -1
- package/dist/drivers/upload_task.cjs +223 -260
- package/dist/drivers/upload_task.cjs.map +1 -1
- package/dist/drivers/upload_task.d.ts +54 -52
- package/dist/drivers/upload_task.js +221 -258
- package/dist/drivers/upload_task.js.map +1 -1
- package/dist/drivers/urls/url.cjs +30 -35
- package/dist/drivers/urls/url.cjs.map +1 -1
- package/dist/drivers/urls/url.js +28 -33
- package/dist/drivers/urls/url.js.map +1 -1
- package/dist/drivers/virtual_storages.cjs +36 -48
- package/dist/drivers/virtual_storages.cjs.map +1 -1
- package/dist/drivers/virtual_storages.d.ts +6 -2
- package/dist/drivers/virtual_storages.js +32 -46
- package/dist/drivers/virtual_storages.js.map +1 -1
- package/dist/helpers/download.cjs +72 -95
- package/dist/helpers/download.cjs.map +1 -1
- package/dist/helpers/download.d.ts +13 -9
- package/dist/helpers/download.js +71 -93
- package/dist/helpers/download.js.map +1 -1
- package/dist/helpers/download_errors.cjs +28 -27
- package/dist/helpers/download_errors.cjs.map +1 -1
- package/dist/helpers/download_errors.d.ts +16 -13
- package/dist/helpers/download_errors.js +28 -26
- package/dist/helpers/download_errors.js.map +1 -1
- package/dist/helpers/validate.cjs +8 -7
- package/dist/helpers/validate.cjs.map +1 -1
- package/dist/helpers/validate.d.ts +4 -1
- package/dist/helpers/validate.js +6 -5
- package/dist/helpers/validate.js.map +1 -1
- package/dist/index.cjs +75 -79
- package/dist/index.d.ts +22 -22
- package/dist/index.js +22 -21
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +238 -249
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +27 -27
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +25 -23
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +26 -25
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +51 -87
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +238 -245
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +295 -289
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +30 -30
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +29 -28
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +86 -150
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +295 -285
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +385 -393
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +34 -34
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +33 -34
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +33 -32
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +78 -129
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +385 -387
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +570 -468
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +82 -82
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +109 -112
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +81 -80
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +243 -264
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +569 -460
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +751 -729
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +67 -67
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +66 -65
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +15 -381
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +749 -718
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
- package/dist/proto-grpc/google/protobuf/duration.js +91 -98
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
- package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
- package/dist/proto-rest/downloadapi.d.ts +85 -91
- package/dist/proto-rest/index.d.ts +11 -16
- package/dist/proto-rest/progressapi.d.ts +130 -140
- package/dist/proto-rest/streamingapi.d.ts +413 -434
- package/package.json +12 -12
- package/dist/clients/constructors.d.ts.map +0 -1
- package/dist/clients/crc32c.d.ts +0 -2
- package/dist/clients/crc32c.d.ts.map +0 -1
- package/dist/clients/download.d.ts.map +0 -1
- package/dist/clients/logs.d.ts.map +0 -1
- package/dist/clients/ls_api.d.ts.map +0 -1
- package/dist/clients/progress.d.ts.map +0 -1
- package/dist/clients/upload.d.ts.map +0 -1
- package/dist/drivers/download_blob/blob_key.d.ts +0 -5
- package/dist/drivers/download_blob/blob_key.d.ts.map +0 -1
- package/dist/drivers/download_blob/download_blob.d.ts.map +0 -1
- package/dist/drivers/download_blob/download_blob_task.d.ts +0 -56
- package/dist/drivers/download_blob/download_blob_task.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/cache.d.ts +0 -82
- package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/file.d.ts +0 -8
- package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +0 -46
- package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/driver.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/driver_id.d.ts +0 -6
- package/dist/drivers/download_blob_url/driver_id.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/snapshot.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/task.d.ts.map +0 -1
- package/dist/drivers/download_url/driver.d.ts.map +0 -1
- package/dist/drivers/download_url/task.d.ts.map +0 -1
- package/dist/drivers/helpers/download_local_handle.d.ts +0 -11
- package/dist/drivers/helpers/download_local_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/download_remote_handle.d.ts +0 -13
- package/dist/drivers/helpers/download_remote_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/files_cache.d.ts +0 -29
- package/dist/drivers/helpers/files_cache.d.ts.map +0 -1
- package/dist/drivers/helpers/helpers.d.ts.map +0 -1
- package/dist/drivers/helpers/logs_handle.d.ts +0 -15
- package/dist/drivers/helpers/logs_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/ls_remote_import_handle.d.ts +0 -8
- package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/ls_storage_entry.d.ts +0 -23
- package/dist/drivers/helpers/ls_storage_entry.d.ts.map +0 -1
- package/dist/drivers/helpers/polling_ops.d.ts.map +0 -1
- package/dist/drivers/helpers/read_file.d.ts +0 -12
- package/dist/drivers/helpers/read_file.d.ts.map +0 -1
- package/dist/drivers/helpers/test_helpers.d.ts +0 -2
- package/dist/drivers/helpers/test_helpers.d.ts.map +0 -1
- package/dist/drivers/logs.d.ts.map +0 -1
- package/dist/drivers/logs_stream.d.ts.map +0 -1
- package/dist/drivers/ls.d.ts.map +0 -1
- package/dist/drivers/types.d.ts.map +0 -1
- package/dist/drivers/upload.d.ts.map +0 -1
- package/dist/drivers/upload_task.d.ts.map +0 -1
- package/dist/drivers/urls/url.d.ts +0 -13
- package/dist/drivers/urls/url.d.ts.map +0 -1
- package/dist/drivers/virtual_storages.d.ts.map +0 -1
- package/dist/helpers/download.d.ts.map +0 -1
- package/dist/helpers/download_errors.d.ts.map +0 -1
- package/dist/helpers/validate.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -46
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +0 -108
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
- package/dist/proto-grpc/google/api/http.d.ts +0 -460
- package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto-rest/downloadapi.d.ts.map +0 -1
- package/dist/proto-rest/index.d.ts.map +0 -1
- package/dist/proto-rest/lsapi.d.ts +0 -148
- package/dist/proto-rest/lsapi.d.ts.map +0 -1
- package/dist/proto-rest/progressapi.d.ts.map +0 -1
- package/dist/proto-rest/streamingapi.d.ts.map +0 -1
- package/dist/proto-rest/uploadapi.d.ts +0 -355
- package/dist/proto-rest/uploadapi.d.ts.map +0 -1
- package/dist/test_env.d.ts +0 -6
- package/dist/test_env.d.ts.map +0 -1
|
@@ -1,203 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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;IAC3D;AAEA,IAAA,MAAM,GAAG,CAAC,GAAW,EAAE,MAAc,EAAA;AACnC,QAAA,OAAO,MAAM,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACpE;IAEA,MAAM,MAAM,CAAC,GAAW,EAAA;QACtB,MAAMC,QAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B;AACD;AAWD;MACa,iBAAiB,CAAA;AAIT,IAAA,MAAA;AACA,IAAA,QAAA;IAJF,MAAM,GAAG,aAAa;IAEvC,WAAA,CACmB,MAAgB,EAChB,QAA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AAG,CAAC,GAAG,CAAC;QACnC;QAAE,OAAO,CAAU,EAAE;AACnB,YAAA,IAAI,CAAC,YAAY,oBAAoB,EAAE;;;AAGrC,gBAAA,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;AACrB,gBAAA,MAAM,IAAI,CAAC,WAAW,EAAE;gBAExB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YACnC;AAEA,YAAA,MAAM,CAAC;QACT;IACF;;IAGQ,MAAM,KAAK,CAAC,GAAW,EAAA;QAC7B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;QAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;AAC7B,QAAA,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC;IACtC;AAEA,IAAA,MAAM,OAAO,GAAA;AACX,QAAA,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;IAChC;AAEA,IAAA,OAAO,MAAM,CAAC,YAAY,CAAC,GAAA;AACzB,QAAA,MAAM,IAAI,CAAC,OAAO,EAAE;IACtB;AACD;AAED;AACA,eAAe,QAAQ,CAAI,IAAyB,EAAE,EAAoB,EAAA;AACxE,IAAA,IAAI;AACF,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,KAAK,SAAS,EAChC,QAAQ,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC;;CAGrD,MAAM,OAAO,KAA+B;AAC1C,SAAO,MAAM,WAAW,KAAK,KAAK,IAAI,CAAC;;CAGzC,KAAK,KAAqB;AACxB,SAAO,KAAK,KAAK,KAAK,UAAU,MAAM,KAAK,OAAO;;CAGpD,MAAM,MAAM,KAAa,MAAkB,MAA6B;AACtE,QAAM,gBAAgB,KAAK,SAAS;AACpC,QAAM,kBAAkB,KAAK,QAAQ,QAAQ,UAAU,KAAK,KAAK,IAAI,EAAE,MAAM,KAAK;;CAGpF,MAAM,OAAO,KAA4B;AACvC,QAAMA,SAAG,GAA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AK,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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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"],"
|
|
1
|
+
{"version":3,"file":"file.cjs","names":["fs"],"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"],"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
|
|
2
|
-
import
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
40
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
export { writeToSparseFile };
|
|
39
|
+
//# sourceMappingURL=file.js.map
|