@backblaze-labs/b2-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -5
- package/README.md +144 -33
- package/dist/_virtual/_b2-sdk-version-json.cjs +4 -0
- package/dist/_virtual/_b2-sdk-version-json.js +4 -0
- package/dist/auth/account-info.d.cts +32 -0
- package/dist/auth/account-info.d.cts.map +1 -1
- package/dist/auth/account-info.d.ts +32 -0
- package/dist/auth/account-info.d.ts.map +1 -1
- package/dist/auth/file.cjs +408 -207
- package/dist/auth/file.cjs.map +1 -1
- package/dist/auth/file.d.cts +77 -3
- package/dist/auth/file.d.cts.map +1 -1
- package/dist/auth/file.d.ts +77 -3
- package/dist/auth/file.d.ts.map +1 -1
- package/dist/auth/file.js +407 -207
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/in-memory.cjs +212 -183
- package/dist/auth/in-memory.cjs.map +1 -1
- package/dist/auth/in-memory.d.cts +8 -0
- package/dist/auth/in-memory.d.cts.map +1 -1
- package/dist/auth/in-memory.d.ts +8 -0
- package/dist/auth/in-memory.d.ts.map +1 -1
- package/dist/auth/in-memory.js +211 -182
- package/dist/auth/in-memory.js.map +1 -1
- package/dist/auth/index.cjs +7 -9
- package/dist/auth/index.d.cts +3 -2
- package/dist/auth/index.d.cts.map +1 -1
- package/dist/auth/index.d.ts +3 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -8
- package/dist/auth/realms.cjs +80 -7
- package/dist/auth/realms.cjs.map +1 -1
- package/dist/auth/realms.d.cts +27 -4
- package/dist/auth/realms.d.cts.map +1 -1
- package/dist/auth/realms.d.ts +27 -4
- package/dist/auth/realms.d.ts.map +1 -1
- package/dist/auth/realms.js +80 -9
- package/dist/auth/realms.js.map +1 -1
- package/dist/auth/upload-url-pool.cjs +55 -51
- package/dist/auth/upload-url-pool.cjs.map +1 -1
- package/dist/auth/upload-url-pool.js +55 -51
- package/dist/auth/upload-url-pool.js.map +1 -1
- package/dist/bucket.cjs +785 -787
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.d.cts +35 -47
- package/dist/bucket.d.cts.map +1 -1
- package/dist/bucket.d.ts +35 -47
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +780 -782
- package/dist/bucket.js.map +1 -1
- package/dist/client.cjs +246 -228
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -17
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +25 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +243 -225
- package/dist/client.js.map +1 -1
- package/dist/copy/large.cjs +114 -71
- package/dist/copy/large.cjs.map +1 -1
- package/dist/copy/large.d.cts +6 -0
- package/dist/copy/large.d.cts.map +1 -1
- package/dist/copy/large.d.ts +6 -0
- package/dist/copy/large.d.ts.map +1 -1
- package/dist/copy/large.js +112 -69
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +89 -0
- package/dist/download/checksum.cjs.map +1 -0
- package/dist/download/checksum.d.cts +40 -0
- package/dist/download/checksum.d.cts.map +1 -0
- package/dist/download/checksum.d.ts +40 -0
- package/dist/download/checksum.d.ts.map +1 -0
- package/dist/download/checksum.js +87 -0
- package/dist/download/checksum.js.map +1 -0
- package/dist/download/parallel.cjs +214 -118
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +5 -1
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +5 -1
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +212 -116
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +188 -97
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts +6 -1
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts +6 -1
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +186 -98
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +699 -243
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +285 -82
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +285 -82
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +678 -261
- package/dist/errors/index.js.map +1 -1
- package/dist/http/retry.cjs +45 -28
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.d.cts +15 -2
- package/dist/http/retry.d.cts.map +1 -1
- package/dist/http/retry.d.ts +15 -2
- package/dist/http/retry.d.ts.map +1 -1
- package/dist/http/retry.js +46 -31
- package/dist/http/retry.js.map +1 -1
- package/dist/http/transport.cjs +438 -140
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +21 -2
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +21 -2
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +437 -140
- package/dist/http/transport.js.map +1 -1
- package/dist/http/url-guard.cjs +154 -89
- package/dist/http/url-guard.cjs.map +1 -1
- package/dist/http/url-guard.d.cts +25 -3
- package/dist/http/url-guard.d.cts.map +1 -1
- package/dist/http/url-guard.d.ts +25 -3
- package/dist/http/url-guard.d.ts.map +1 -1
- package/dist/http/url-guard.js +152 -90
- package/dist/http/url-guard.js.map +1 -1
- package/dist/http/user-agent.cjs +84 -44
- package/dist/http/user-agent.cjs.map +1 -1
- package/dist/http/user-agent.js +84 -46
- package/dist/http/user-agent.js.map +1 -1
- package/dist/index.cjs +101 -77
- package/dist/index.d.cts +27 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +27 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -71
- package/dist/internal/b2-naming.cjs +66 -0
- package/dist/internal/b2-naming.cjs.map +1 -0
- package/dist/internal/b2-naming.d.cts +43 -0
- package/dist/internal/b2-naming.d.cts.map +1 -0
- package/dist/internal/b2-naming.d.ts +43 -0
- package/dist/internal/b2-naming.d.ts.map +1 -0
- package/dist/internal/b2-naming.js +60 -0
- package/dist/internal/b2-naming.js.map +1 -0
- package/dist/internal/upload-retry-options.cjs +21 -0
- package/dist/internal/upload-retry-options.cjs.map +1 -0
- package/dist/internal/upload-retry-options.d.cts +12 -0
- package/dist/internal/upload-retry-options.d.cts.map +1 -0
- package/dist/internal/upload-retry-options.d.ts +12 -0
- package/dist/internal/upload-retry-options.d.ts.map +1 -0
- package/dist/internal/upload-retry-options.js +21 -0
- package/dist/internal/upload-retry-options.js.map +1 -0
- package/dist/internal/url-redaction.cjs +31 -0
- package/dist/internal/url-redaction.cjs.map +1 -0
- package/dist/internal/url-redaction.d.cts +17 -0
- package/dist/internal/url-redaction.d.cts.map +1 -0
- package/dist/internal/url-redaction.d.ts +17 -0
- package/dist/internal/url-redaction.d.ts.map +1 -0
- package/dist/internal/url-redaction.js +31 -0
- package/dist/internal/url-redaction.js.map +1 -0
- package/dist/notifications/index.cjs +4 -6
- package/dist/notifications/index.d.cts +1 -1
- package/dist/notifications/index.d.cts.map +1 -1
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +1 -6
- package/dist/notifications/webhook.cjs +195 -85
- package/dist/notifications/webhook.cjs.map +1 -1
- package/dist/notifications/webhook.d.cts.map +1 -1
- package/dist/notifications/webhook.d.ts.map +1 -1
- package/dist/notifications/webhook.js +195 -87
- package/dist/notifications/webhook.js.map +1 -1
- package/dist/object.cjs +253 -210
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +9 -55
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +9 -55
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +249 -206
- package/dist/object.js.map +1 -1
- package/dist/raw/encoding.cjs +74 -35
- package/dist/raw/encoding.cjs.map +1 -1
- package/dist/raw/encoding.js +74 -38
- package/dist/raw/encoding.js.map +1 -1
- package/dist/raw/index.cjs +678 -587
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +121 -18
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +121 -18
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +674 -589
- package/dist/raw/index.js.map +1 -1
- package/dist/s3/index.cjs +355 -18
- package/dist/s3/index.cjs.map +1 -1
- package/dist/s3/index.d.cts +233 -5
- package/dist/s3/index.d.cts.map +1 -1
- package/dist/s3/index.d.ts +233 -5
- package/dist/s3/index.d.ts.map +1 -1
- package/dist/s3/index.js +351 -22
- package/dist/s3/index.js.map +1 -1
- package/dist/s3/sigv4.cjs +149 -0
- package/dist/s3/sigv4.cjs.map +1 -0
- package/dist/s3/sigv4.d.cts +43 -0
- package/dist/s3/sigv4.d.cts.map +1 -0
- package/dist/s3/sigv4.d.ts +43 -0
- package/dist/s3/sigv4.d.ts.map +1 -0
- package/dist/s3/sigv4.js +148 -0
- package/dist/s3/sigv4.js.map +1 -0
- package/dist/s3/validation.cjs +69 -0
- package/dist/s3/validation.cjs.map +1 -0
- package/dist/s3/validation.d.cts +43 -0
- package/dist/s3/validation.d.cts.map +1 -0
- package/dist/s3/validation.d.ts +43 -0
- package/dist/s3/validation.d.ts.map +1 -0
- package/dist/s3/validation.js +66 -0
- package/dist/s3/validation.js.map +1 -0
- package/dist/simulator/capabilities.cjs +63 -48
- package/dist/simulator/capabilities.cjs.map +1 -1
- package/dist/simulator/capabilities.js +63 -49
- package/dist/simulator/capabilities.js.map +1 -1
- package/dist/simulator/index.cjs +2124 -1548
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +79 -11
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +79 -11
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +2112 -1546
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/validation.cjs +191 -153
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +3 -21
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +3 -21
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +188 -162
- package/dist/simulator/validation.js.map +1 -1
- package/dist/streams/collect.cjs +74 -24
- package/dist/streams/collect.cjs.map +1 -1
- package/dist/streams/collect.d.cts +14 -1
- package/dist/streams/collect.d.cts.map +1 -1
- package/dist/streams/collect.d.ts +14 -1
- package/dist/streams/collect.d.ts.map +1 -1
- package/dist/streams/collect.js +74 -25
- package/dist/streams/collect.js.map +1 -1
- package/dist/streams/file-source.cjs +287 -0
- package/dist/streams/file-source.cjs.map +1 -0
- package/dist/streams/file-source.d.cts +96 -0
- package/dist/streams/file-source.d.cts.map +1 -0
- package/dist/streams/file-source.d.ts +96 -0
- package/dist/streams/file-source.d.ts.map +1 -0
- package/dist/streams/file-source.js +286 -0
- package/dist/streams/file-source.js.map +1 -0
- package/dist/streams/hash.cjs +207 -115
- package/dist/streams/hash.cjs.map +1 -1
- package/dist/streams/hash.d.cts +5 -4
- package/dist/streams/hash.d.cts.map +1 -1
- package/dist/streams/hash.d.ts +5 -4
- package/dist/streams/hash.d.ts.map +1 -1
- package/dist/streams/hash.js +208 -95
- package/dist/streams/hash.js.map +1 -1
- package/dist/streams/index.cjs +12 -12
- package/dist/streams/index.d.cts +3 -3
- package/dist/streams/index.d.cts.map +1 -1
- package/dist/streams/index.d.ts +3 -3
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +2 -10
- package/dist/streams/progress.cjs +60 -46
- package/dist/streams/progress.cjs.map +1 -1
- package/dist/streams/progress.js +60 -46
- package/dist/streams/progress.js.map +1 -1
- package/dist/streams/source.cjs +316 -146
- package/dist/streams/source.cjs.map +1 -1
- package/dist/streams/source.d.cts +56 -18
- package/dist/streams/source.d.cts.map +1 -1
- package/dist/streams/source.d.ts +56 -18
- package/dist/streams/source.d.ts.map +1 -1
- package/dist/streams/source.js +312 -149
- package/dist/streams/source.js.map +1 -1
- package/dist/sync/actions/index.cjs +236 -184
- package/dist/sync/actions/index.cjs.map +1 -1
- package/dist/sync/actions/index.d.cts +29 -21
- package/dist/sync/actions/index.d.cts.map +1 -1
- package/dist/sync/actions/index.d.ts +29 -21
- package/dist/sync/actions/index.d.ts.map +1 -1
- package/dist/sync/actions/index.js +236 -190
- package/dist/sync/actions/index.js.map +1 -1
- package/dist/sync/b2-sha1-reader.cjs +148 -0
- package/dist/sync/b2-sha1-reader.cjs.map +1 -0
- package/dist/sync/b2-sha1-reader.d.cts +58 -0
- package/dist/sync/b2-sha1-reader.d.cts.map +1 -0
- package/dist/sync/b2-sha1-reader.d.ts +58 -0
- package/dist/sync/b2-sha1-reader.d.ts.map +1 -0
- package/dist/sync/b2-sha1-reader.js +145 -0
- package/dist/sync/b2-sha1-reader.js.map +1 -0
- package/dist/sync/download-staging.cjs +265 -0
- package/dist/sync/download-staging.cjs.map +1 -0
- package/dist/sync/download-staging.d.cts +54 -0
- package/dist/sync/download-staging.d.cts.map +1 -0
- package/dist/sync/download-staging.d.ts +54 -0
- package/dist/sync/download-staging.d.ts.map +1 -0
- package/dist/sync/download-staging.js +259 -0
- package/dist/sync/download-staging.js.map +1 -0
- package/dist/sync/filesystem-errors.cjs +32 -0
- package/dist/sync/filesystem-errors.cjs.map +1 -0
- package/dist/sync/filesystem-errors.d.cts +8 -0
- package/dist/sync/filesystem-errors.d.cts.map +1 -0
- package/dist/sync/filesystem-errors.d.ts +8 -0
- package/dist/sync/filesystem-errors.d.ts.map +1 -0
- package/dist/sync/filesystem-errors.js +32 -0
- package/dist/sync/filesystem-errors.js.map +1 -0
- package/dist/sync/filters.cjs +217 -0
- package/dist/sync/filters.cjs.map +1 -0
- package/dist/sync/filters.d.cts +51 -0
- package/dist/sync/filters.d.cts.map +1 -0
- package/dist/sync/filters.d.ts +51 -0
- package/dist/sync/filters.d.ts.map +1 -0
- package/dist/sync/filters.js +213 -0
- package/dist/sync/filters.js.map +1 -0
- package/dist/sync/index.cjs +39 -22
- package/dist/sync/index.d.cts +14 -9
- package/dist/sync/index.d.cts.map +1 -1
- package/dist/sync/index.d.ts +14 -9
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +9 -20
- package/dist/sync/local-file-identity.cjs +61 -0
- package/dist/sync/local-file-identity.cjs.map +1 -0
- package/dist/sync/local-file-identity.d.cts +37 -0
- package/dist/sync/local-file-identity.d.cts.map +1 -0
- package/dist/sync/local-file-identity.d.ts +37 -0
- package/dist/sync/local-file-identity.d.ts.map +1 -0
- package/dist/sync/local-file-identity.js +60 -0
- package/dist/sync/local-file-identity.js.map +1 -0
- package/dist/sync/local-file-io.cjs +364 -0
- package/dist/sync/local-file-io.cjs.map +1 -0
- package/dist/sync/local-file-io.d.cts +75 -0
- package/dist/sync/local-file-io.d.cts.map +1 -0
- package/dist/sync/local-file-io.d.ts +75 -0
- package/dist/sync/local-file-io.d.ts.map +1 -0
- package/dist/sync/local-file-io.js +360 -0
- package/dist/sync/local-file-io.js.map +1 -0
- package/dist/sync/local-filesystem-root.cjs +27 -0
- package/dist/sync/local-filesystem-root.cjs.map +1 -0
- package/dist/sync/local-filesystem-root.d.cts +18 -0
- package/dist/sync/local-filesystem-root.d.cts.map +1 -0
- package/dist/sync/local-filesystem-root.d.ts +18 -0
- package/dist/sync/local-filesystem-root.d.ts.map +1 -0
- package/dist/sync/local-filesystem-root.js +26 -0
- package/dist/sync/local-filesystem-root.js.map +1 -0
- package/dist/sync/local-sha1.cjs +119 -0
- package/dist/sync/local-sha1.cjs.map +1 -0
- package/dist/sync/local-sha1.d.cts +39 -0
- package/dist/sync/local-sha1.d.cts.map +1 -0
- package/dist/sync/local-sha1.d.ts +39 -0
- package/dist/sync/local-sha1.d.ts.map +1 -0
- package/dist/sync/local-sha1.js +117 -0
- package/dist/sync/local-sha1.js.map +1 -0
- package/dist/sync/pairing.cjs +118 -29
- package/dist/sync/pairing.cjs.map +1 -1
- package/dist/sync/pairing.d.cts +7 -2
- package/dist/sync/pairing.d.cts.map +1 -1
- package/dist/sync/pairing.d.ts +7 -2
- package/dist/sync/pairing.d.ts.map +1 -1
- package/dist/sync/pairing.js +120 -31
- package/dist/sync/pairing.js.map +1 -1
- package/dist/sync/path-order.cjs +30 -0
- package/dist/sync/path-order.cjs.map +1 -0
- package/dist/sync/path-order.d.cts +28 -0
- package/dist/sync/path-order.d.cts.map +1 -0
- package/dist/sync/path-order.d.ts +28 -0
- package/dist/sync/path-order.d.ts.map +1 -0
- package/dist/sync/path-order.js +29 -0
- package/dist/sync/path-order.js.map +1 -0
- package/dist/sync/path-safety.cjs +111 -0
- package/dist/sync/path-safety.cjs.map +1 -0
- package/dist/sync/path-safety.d.cts +78 -0
- package/dist/sync/path-safety.d.cts.map +1 -0
- package/dist/sync/path-safety.d.ts +78 -0
- package/dist/sync/path-safety.d.ts.map +1 -0
- package/dist/sync/path-safety.js +105 -0
- package/dist/sync/path-safety.js.map +1 -0
- package/dist/sync/paths.d.cts +19 -0
- package/dist/sync/paths.d.cts.map +1 -0
- package/dist/sync/paths.d.ts +19 -0
- package/dist/sync/paths.d.ts.map +1 -0
- package/dist/sync/policies/compare.cjs +389 -11
- package/dist/sync/policies/compare.cjs.map +1 -1
- package/dist/sync/policies/compare.d.cts +100 -2
- package/dist/sync/policies/compare.d.cts.map +1 -1
- package/dist/sync/policies/compare.d.ts +100 -2
- package/dist/sync/policies/compare.d.ts.map +1 -1
- package/dist/sync/policies/compare.js +387 -13
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +76 -65
- package/dist/sync/policies/index.cjs.map +1 -1
- package/dist/sync/policies/index.d.cts +35 -6
- package/dist/sync/policies/index.d.cts.map +1 -1
- package/dist/sync/policies/index.d.ts +35 -6
- package/dist/sync/policies/index.d.ts.map +1 -1
- package/dist/sync/policies/index.js +76 -65
- package/dist/sync/policies/index.js.map +1 -1
- package/dist/sync/prefix.cjs +96 -0
- package/dist/sync/prefix.cjs.map +1 -0
- package/dist/sync/prefix.d.cts +55 -0
- package/dist/sync/prefix.d.cts.map +1 -0
- package/dist/sync/prefix.d.ts +55 -0
- package/dist/sync/prefix.d.ts.map +1 -0
- package/dist/sync/prefix.js +92 -0
- package/dist/sync/prefix.js.map +1 -0
- package/dist/sync/regexp-safety.cjs +192 -0
- package/dist/sync/regexp-safety.cjs.map +1 -0
- package/dist/sync/regexp-safety.d.cts +29 -0
- package/dist/sync/regexp-safety.d.cts.map +1 -0
- package/dist/sync/regexp-safety.d.ts +29 -0
- package/dist/sync/regexp-safety.d.ts.map +1 -0
- package/dist/sync/regexp-safety.js +190 -0
- package/dist/sync/regexp-safety.js.map +1 -0
- package/dist/sync/scan-events.cjs +33 -0
- package/dist/sync/scan-events.cjs.map +1 -0
- package/dist/sync/scan-events.d.cts +17 -0
- package/dist/sync/scan-events.d.cts.map +1 -0
- package/dist/sync/scan-events.d.ts +17 -0
- package/dist/sync/scan-events.d.ts.map +1 -0
- package/dist/sync/scan-events.js +32 -0
- package/dist/sync/scan-events.js.map +1 -0
- package/dist/sync/scan-limit.cjs +33 -0
- package/dist/sync/scan-limit.cjs.map +1 -0
- package/dist/sync/scan-limit.d.cts +21 -0
- package/dist/sync/scan-limit.d.cts.map +1 -0
- package/dist/sync/scan-limit.d.ts +21 -0
- package/dist/sync/scan-limit.d.ts.map +1 -0
- package/dist/sync/scan-limit.js +31 -0
- package/dist/sync/scan-limit.js.map +1 -0
- package/dist/sync/scanners/b2.cjs +239 -55
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.d.cts +26 -7
- package/dist/sync/scanners/b2.d.cts.map +1 -1
- package/dist/sync/scanners/b2.d.ts +26 -7
- package/dist/sync/scanners/b2.d.ts.map +1 -1
- package/dist/sync/scanners/b2.js +239 -55
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs +215 -56
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.d.cts +22 -7
- package/dist/sync/scanners/local.d.cts.map +1 -1
- package/dist/sync/scanners/local.d.ts +22 -7
- package/dist/sync/scanners/local.d.ts.map +1 -1
- package/dist/sync/scanners/local.js +216 -57
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/sha1-metadata.cjs +94 -0
- package/dist/sync/sha1-metadata.cjs.map +1 -0
- package/dist/sync/sha1-metadata.d.cts +82 -0
- package/dist/sync/sha1-metadata.d.cts.map +1 -0
- package/dist/sync/sha1-metadata.d.ts +82 -0
- package/dist/sync/sha1-metadata.d.ts.map +1 -0
- package/dist/sync/sha1-metadata.js +89 -0
- package/dist/sync/sha1-metadata.js.map +1 -0
- package/dist/sync/sha1-options.cjs +23 -0
- package/dist/sync/sha1-options.cjs.map +1 -0
- package/dist/sync/sha1-options.d.cts +14 -0
- package/dist/sync/sha1-options.d.cts.map +1 -0
- package/dist/sync/sha1-options.d.ts +14 -0
- package/dist/sync/sha1-options.d.ts.map +1 -0
- package/dist/sync/sha1-options.js +21 -0
- package/dist/sync/sha1-options.js.map +1 -0
- package/dist/sync/synchronizer.cjs +782 -197
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.d.cts +47 -1
- package/dist/sync/synchronizer.d.cts.map +1 -1
- package/dist/sync/synchronizer.d.ts +47 -1
- package/dist/sync/synchronizer.d.ts.map +1 -1
- package/dist/sync/synchronizer.js +779 -173
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/sync/types.d.cts +208 -16
- package/dist/sync/types.d.cts.map +1 -1
- package/dist/sync/types.d.ts +208 -16
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/types/auth.cjs +76 -56
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +67 -9
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +67 -9
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +77 -57
- package/dist/types/auth.js.map +1 -1
- package/dist/types/bucket.cjs +74 -38
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.js +75 -41
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/encryption.cjs +364 -327
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +16 -0
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +16 -0
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +364 -310
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +47 -0
- package/dist/types/errors.cjs.map +1 -0
- package/dist/types/errors.d.cts +13 -4
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +13 -4
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +47 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/file.cjs +36 -19
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +2 -2
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +2 -2
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js +37 -21
- package/dist/types/file.js.map +1 -1
- package/dist/types/ids.cjs +53 -9
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.js +54 -15
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +12 -11
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +12 -11
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key.d.cts +44 -8
- package/dist/types/key.d.cts.map +1 -1
- package/dist/types/key.d.ts +44 -8
- package/dist/types/key.d.ts.map +1 -1
- package/dist/types/lock.cjs +33 -13
- package/dist/types/lock.cjs.map +1 -1
- package/dist/types/lock.js +34 -15
- package/dist/types/lock.js.map +1 -1
- package/dist/types/notifications.cjs +44 -22
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.js +45 -23
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/upload.d.cts +39 -5
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +39 -5
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +91 -0
- package/dist/upload/abort-scope.cjs.map +1 -0
- package/dist/upload/abort-scope.d.cts +48 -0
- package/dist/upload/abort-scope.d.cts.map +1 -0
- package/dist/upload/abort-scope.d.ts +48 -0
- package/dist/upload/abort-scope.d.ts.map +1 -0
- package/dist/upload/abort-scope.js +88 -0
- package/dist/upload/abort-scope.js.map +1 -0
- package/dist/upload/cancel.cjs +183 -8
- package/dist/upload/cancel.cjs.map +1 -1
- package/dist/upload/cancel.d.cts +110 -2
- package/dist/upload/cancel.d.cts.map +1 -1
- package/dist/upload/cancel.d.ts +110 -2
- package/dist/upload/cancel.d.ts.map +1 -1
- package/dist/upload/cancel.js +178 -9
- package/dist/upload/cancel.js.map +1 -1
- package/dist/upload/concurrency.cjs +79 -52
- package/dist/upload/concurrency.cjs.map +1 -1
- package/dist/upload/concurrency.js +79 -53
- package/dist/upload/concurrency.js.map +1 -1
- package/dist/upload/finish.cjs +59 -0
- package/dist/upload/finish.cjs.map +1 -0
- package/dist/upload/finish.d.cts +26 -0
- package/dist/upload/finish.d.cts.map +1 -0
- package/dist/upload/finish.d.ts +26 -0
- package/dist/upload/finish.d.ts.map +1 -0
- package/dist/upload/finish.js +59 -0
- package/dist/upload/finish.js.map +1 -0
- package/dist/upload/large.cjs +301 -218
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +76 -9
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +76 -9
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +301 -218
- package/dist/upload/large.js.map +1 -1
- package/dist/upload/options.cjs +28 -0
- package/dist/upload/options.cjs.map +1 -0
- package/dist/upload/options.d.cts +104 -0
- package/dist/upload/options.d.cts.map +1 -0
- package/dist/upload/options.d.ts +104 -0
- package/dist/upload/options.d.ts.map +1 -0
- package/dist/upload/options.js +27 -0
- package/dist/upload/options.js.map +1 -0
- package/dist/upload/resume.cjs +333 -33
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +82 -12
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +82 -12
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +330 -33
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +186 -0
- package/dist/upload/retry.cjs.map +1 -0
- package/dist/upload/retry.d.cts +127 -0
- package/dist/upload/retry.d.cts.map +1 -0
- package/dist/upload/retry.d.ts +127 -0
- package/dist/upload/retry.d.ts.map +1 -0
- package/dist/upload/retry.js +182 -0
- package/dist/upload/retry.js.map +1 -0
- package/dist/upload/single.cjs +68 -44
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +2 -1
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +2 -1
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +68 -44
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +317 -193
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +3 -1
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +3 -1
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +316 -192
- package/dist/upload/stream.js.map +1 -1
- package/dist/util/best-effort.cjs +42 -8
- package/dist/util/best-effort.cjs.map +1 -1
- package/dist/util/best-effort.d.cts +2 -1
- package/dist/util/best-effort.d.cts.map +1 -1
- package/dist/util/best-effort.d.ts +2 -1
- package/dist/util/best-effort.d.ts.map +1 -1
- package/dist/util/best-effort.js +43 -9
- package/dist/util/best-effort.js.map +1 -1
- package/dist/util/bytes.cjs +23 -0
- package/dist/util/bytes.cjs.map +1 -0
- package/dist/util/bytes.d.cts +15 -0
- package/dist/util/bytes.d.cts.map +1 -0
- package/dist/util/bytes.d.ts +15 -0
- package/dist/util/bytes.d.ts.map +1 -0
- package/dist/util/bytes.js +23 -0
- package/dist/util/bytes.js.map +1 -0
- package/dist/util/crypto.cjs +68 -0
- package/dist/util/crypto.cjs.map +1 -0
- package/dist/util/crypto.d.cts +26 -0
- package/dist/util/crypto.d.cts.map +1 -0
- package/dist/util/crypto.d.ts +26 -0
- package/dist/util/crypto.d.ts.map +1 -0
- package/dist/util/crypto.js +66 -0
- package/dist/util/crypto.js.map +1 -0
- package/dist/util/defaults.cjs +25 -9
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.js +26 -11
- package/dist/util/defaults.js.map +1 -1
- package/dist/util/error-reason.cjs +41 -0
- package/dist/util/error-reason.cjs.map +1 -0
- package/dist/util/error-reason.d.cts +9 -0
- package/dist/util/error-reason.d.cts.map +1 -0
- package/dist/util/error-reason.d.ts +9 -0
- package/dist/util/error-reason.d.ts.map +1 -0
- package/dist/util/error-reason.js +41 -0
- package/dist/util/error-reason.js.map +1 -0
- package/dist/util/http.cjs +23 -0
- package/dist/util/http.cjs.map +1 -0
- package/dist/util/http.d.cts +13 -0
- package/dist/util/http.d.cts.map +1 -0
- package/dist/util/http.d.ts +13 -0
- package/dist/util/http.d.ts.map +1 -0
- package/dist/util/http.js +23 -0
- package/dist/util/http.js.map +1 -0
- package/dist/util/normalize.cjs +66 -7
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.js +67 -10
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +63 -14
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.js +64 -16
- package/dist/util/paginator.js.map +1 -1
- package/dist/util/plan-ranges.cjs +47 -22
- package/dist/util/plan-ranges.cjs.map +1 -1
- package/dist/util/plan-ranges.js +48 -24
- package/dist/util/plan-ranges.js.map +1 -1
- package/dist/util/sha1.cjs +27 -0
- package/dist/util/sha1.cjs.map +1 -0
- package/dist/util/sha1.d.cts +17 -0
- package/dist/util/sha1.d.cts.map +1 -0
- package/dist/util/sha1.d.ts +17 -0
- package/dist/util/sha1.d.ts.map +1 -0
- package/dist/util/sha1.js +26 -0
- package/dist/util/sha1.js.map +1 -0
- package/dist/util/text-codec.cjs +29 -5
- package/dist/util/text-codec.cjs.map +1 -1
- package/dist/util/text-codec.js +30 -7
- package/dist/util/text-codec.js.map +1 -1
- package/dist/util/to-error.cjs +18 -4
- package/dist/util/to-error.cjs.map +1 -1
- package/dist/util/to-error.js +19 -5
- package/dist/util/to-error.js.map +1 -1
- package/dist/version.cjs +17 -5
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +3 -3
- package/dist/version.d.ts +3 -3
- package/dist/version.js +19 -6
- package/dist/version.js.map +1 -1
- package/package.json +19 -16
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notifications/index.cjs.map +0 -1
- package/dist/notifications/index.js.map +0 -1
- package/dist/package.json.cjs +0 -9
- package/dist/package.json.cjs.map +0 -1
- package/dist/package.json.js +0 -9
- package/dist/package.json.js.map +0 -1
- package/dist/streams/index.cjs.map +0 -1
- package/dist/streams/index.js.map +0 -1
- package/dist/sync/index.cjs.map +0 -1
- package/dist/sync/index.js.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const require_errors_index = require("../errors/index.cjs");
|
|
2
|
+
const require_hash = require("../streams/hash.cjs");
|
|
3
|
+
const require_sha1 = require("../util/sha1.cjs");
|
|
4
|
+
//#region src/download/checksum.ts
|
|
5
|
+
/**
|
|
6
|
+
* Client-side checksum helpers for download streams.
|
|
7
|
+
*
|
|
8
|
+
* B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file
|
|
9
|
+
* checksum is available. These helpers verify streamed bytes against that
|
|
10
|
+
* header without buffering the full response in memory.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Builds the typed error used when downloaded bytes fail SHA-1 verification.
|
|
16
|
+
*
|
|
17
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
18
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
19
|
+
*
|
|
20
|
+
* @returns A typed checksum mismatch error.
|
|
21
|
+
*/
|
|
22
|
+
function createDownloadChecksumMismatchError(expectedSha1, actualSha1) {
|
|
23
|
+
return new require_errors_index.ChecksumMismatchError({
|
|
24
|
+
status: 400,
|
|
25
|
+
code: "bad_sha1_checksum",
|
|
26
|
+
message: `Downloaded content SHA-1 mismatch: expected ${expectedSha1.toLowerCase()}, got ${actualSha1.toLowerCase()}`
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Throws when a computed download SHA-1 does not match the expected value.
|
|
31
|
+
*
|
|
32
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
33
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
34
|
+
*
|
|
35
|
+
* @throws ChecksumMismatchError when the two digests differ.
|
|
36
|
+
*/
|
|
37
|
+
function assertDownloadSha1(expectedSha1, actualSha1) {
|
|
38
|
+
if (actualSha1.toLowerCase() !== expectedSha1.toLowerCase()) throw createDownloadChecksumMismatchError(expectedSha1, actualSha1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Throws when two range responses disagree about the expected whole-file SHA-1.
|
|
42
|
+
*
|
|
43
|
+
* @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.
|
|
44
|
+
* @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.
|
|
45
|
+
*
|
|
46
|
+
* @throws ChecksumMismatchError when the two header states differ.
|
|
47
|
+
*/
|
|
48
|
+
function assertDownloadSha1HeaderAgreement(expectedSha1, actualSha1) {
|
|
49
|
+
if (expectedSha1 === actualSha1) return;
|
|
50
|
+
throw new require_errors_index.ChecksumMismatchError({
|
|
51
|
+
status: 400,
|
|
52
|
+
code: "bad_sha1_checksum",
|
|
53
|
+
message: `Downloaded content SHA-1 header mismatch: expected ${formatSha1ForMessage(expectedSha1)}, got ${formatSha1ForMessage(actualSha1)}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wraps a download stream with whole-body SHA-1 verification.
|
|
58
|
+
*
|
|
59
|
+
* If B2 did not provide a verifiable whole-file SHA-1 (for example,
|
|
60
|
+
* multipart-finished files report `none`), the original stream is returned.
|
|
61
|
+
*
|
|
62
|
+
* @param body - Download response body.
|
|
63
|
+
* @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.
|
|
64
|
+
*
|
|
65
|
+
* @returns A stream that emits the same bytes and errors on checksum mismatch.
|
|
66
|
+
*/
|
|
67
|
+
function verifyDownloadStream(body, expectedSha1) {
|
|
68
|
+
if (!require_sha1.isVerifiableSha1(expectedSha1)) return body;
|
|
69
|
+
const sha1 = new require_hash.IncrementalSha1();
|
|
70
|
+
const transform = new TransformStream({
|
|
71
|
+
async transform(chunk, controller) {
|
|
72
|
+
await sha1.update(chunk);
|
|
73
|
+
controller.enqueue(chunk);
|
|
74
|
+
},
|
|
75
|
+
async flush() {
|
|
76
|
+
assertDownloadSha1(expectedSha1, await sha1.digest());
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return body.pipeThrough(transform);
|
|
80
|
+
}
|
|
81
|
+
function formatSha1ForMessage(sha1) {
|
|
82
|
+
return sha1 === null ? "missing or unverifiable" : sha1.toLowerCase();
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.assertDownloadSha1 = assertDownloadSha1;
|
|
86
|
+
exports.assertDownloadSha1HeaderAgreement = assertDownloadSha1HeaderAgreement;
|
|
87
|
+
exports.verifyDownloadStream = verifyDownloadStream;
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=checksum.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.cjs","names":[],"sources":["../../src/download/checksum.ts"],"sourcesContent":["/**\n * Client-side checksum helpers for download streams.\n *\n * B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file\n * checksum is available. These helpers verify streamed bytes against that\n * header without buffering the full response in memory.\n *\n * @packageDocumentation\n */\n\nimport { ChecksumMismatchError } from '../errors/index.ts'\nimport { IncrementalSha1 } from '../streams/hash.ts'\nimport { isVerifiableSha1 } from '../util/sha1.ts'\n\n/**\n * Builds the typed error used when downloaded bytes fail SHA-1 verification.\n *\n * @param expectedSha1 - SHA-1 digest advertised by the download response.\n * @param actualSha1 - SHA-1 digest computed from the downloaded bytes.\n *\n * @returns A typed checksum mismatch error.\n */\nfunction createDownloadChecksumMismatchError(\n expectedSha1: string,\n actualSha1: string,\n): ChecksumMismatchError {\n const expected = expectedSha1.toLowerCase()\n const actual = actualSha1.toLowerCase()\n return new ChecksumMismatchError({\n status: 400,\n code: 'bad_sha1_checksum',\n message: `Downloaded content SHA-1 mismatch: expected ${expected}, got ${actual}`,\n })\n}\n\n/**\n * Throws when a computed download SHA-1 does not match the expected value.\n *\n * @param expectedSha1 - SHA-1 digest advertised by the download response.\n * @param actualSha1 - SHA-1 digest computed from the downloaded bytes.\n *\n * @throws ChecksumMismatchError when the two digests differ.\n */\nexport function assertDownloadSha1(expectedSha1: string, actualSha1: string): void {\n if (actualSha1.toLowerCase() !== expectedSha1.toLowerCase()) {\n throw createDownloadChecksumMismatchError(expectedSha1, actualSha1)\n }\n}\n\n/**\n * Throws when two range responses disagree about the expected whole-file SHA-1.\n *\n * @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.\n * @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.\n *\n * @throws ChecksumMismatchError when the two header states differ.\n */\nexport function assertDownloadSha1HeaderAgreement(\n expectedSha1: string | null,\n actualSha1: string | null,\n): void {\n if (expectedSha1 === actualSha1) return\n const expected = formatSha1ForMessage(expectedSha1)\n const actual = formatSha1ForMessage(actualSha1)\n throw new ChecksumMismatchError({\n status: 400,\n code: 'bad_sha1_checksum',\n message: `Downloaded content SHA-1 header mismatch: expected ${expected}, got ${actual}`,\n })\n}\n\n/**\n * Wraps a download stream with whole-body SHA-1 verification.\n *\n * If B2 did not provide a verifiable whole-file SHA-1 (for example,\n * multipart-finished files report `none`), the original stream is returned.\n *\n * @param body - Download response body.\n * @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.\n *\n * @returns A stream that emits the same bytes and errors on checksum mismatch.\n */\nexport function verifyDownloadStream(\n body: ReadableStream<Uint8Array>,\n expectedSha1: string | null,\n): ReadableStream<Uint8Array> {\n if (!isVerifiableSha1(expectedSha1)) return body\n\n const sha1 = new IncrementalSha1()\n const transform = new TransformStream<Uint8Array, Uint8Array>({\n async transform(chunk, controller) {\n await sha1.update(chunk)\n controller.enqueue(chunk)\n },\n async flush() {\n assertDownloadSha1(expectedSha1, await sha1.digest())\n },\n })\n return body.pipeThrough(transform)\n}\n\nfunction formatSha1ForMessage(sha1: string | null): string {\n return sha1 === null ? 'missing or unverifiable' : sha1.toLowerCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,oCACP,cACA,YACuB;CAGvB,OAAO,IAAI,qBAAA,sBAAsB;EAC/B,QAAQ;EACR,MAAM;EACN,SAAS,+CALM,aAAa,YAK4B,EAAS,QAJpD,WAAW,YAIiD;CAC3E,CAAC;AACH;;;;;;;;;AAUA,SAAgB,mBAAmB,cAAsB,YAA0B;CACjF,IAAI,WAAW,YAAY,MAAM,aAAa,YAAY,GACxD,MAAM,oCAAoC,cAAc,UAAU;AAEtE;;;;;;;;;AAUA,SAAgB,kCACd,cACA,YACM;CACN,IAAI,iBAAiB,YAAY;CAGjC,MAAM,IAAI,qBAAA,sBAAsB;EAC9B,QAAQ;EACR,MAAM;EACN,SAAS,sDALM,qBAAqB,YAK2B,EAAS,QAJ3D,qBAAqB,UAI8C;CAClF,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,qBACd,MACA,cAC4B;CAC5B,IAAI,CAAC,aAAA,iBAAiB,YAAY,GAAG,OAAO;CAE5C,MAAM,OAAO,IAAI,aAAA,gBAAgB;CACjC,MAAM,YAAY,IAAI,gBAAwC;EAC5D,MAAM,UAAU,OAAO,YAAY;GACjC,MAAM,KAAK,OAAO,KAAK;GACvB,WAAW,QAAQ,KAAK;EAC1B;EACA,MAAM,QAAQ;GACZ,mBAAmB,cAAc,MAAM,KAAK,OAAO,CAAC;EACtD;CACF,CAAC;CACD,OAAO,KAAK,YAAY,SAAS;AACnC;AAEA,SAAS,qBAAqB,MAA6B;CACzD,OAAO,SAAS,OAAO,4BAA4B,KAAK,YAAY;AACtE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side checksum helpers for download streams.
|
|
3
|
+
*
|
|
4
|
+
* B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file
|
|
5
|
+
* checksum is available. These helpers verify streamed bytes against that
|
|
6
|
+
* header without buffering the full response in memory.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Throws when a computed download SHA-1 does not match the expected value.
|
|
12
|
+
*
|
|
13
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
14
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
15
|
+
*
|
|
16
|
+
* @throws ChecksumMismatchError when the two digests differ.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertDownloadSha1(expectedSha1: string, actualSha1: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Throws when two range responses disagree about the expected whole-file SHA-1.
|
|
21
|
+
*
|
|
22
|
+
* @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.
|
|
23
|
+
* @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.
|
|
24
|
+
*
|
|
25
|
+
* @throws ChecksumMismatchError when the two header states differ.
|
|
26
|
+
*/
|
|
27
|
+
export declare function assertDownloadSha1HeaderAgreement(expectedSha1: string | null, actualSha1: string | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a download stream with whole-body SHA-1 verification.
|
|
30
|
+
*
|
|
31
|
+
* If B2 did not provide a verifiable whole-file SHA-1 (for example,
|
|
32
|
+
* multipart-finished files report `none`), the original stream is returned.
|
|
33
|
+
*
|
|
34
|
+
* @param body - Download response body.
|
|
35
|
+
* @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.
|
|
36
|
+
*
|
|
37
|
+
* @returns A stream that emits the same bytes and errors on checksum mismatch.
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyDownloadStream(body: ReadableStream<Uint8Array>, expectedSha1: string | null): ReadableStream<Uint8Array>;
|
|
40
|
+
//# sourceMappingURL=checksum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../../src/download/checksum.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2BH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAIjF;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,IAAI,CASN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,YAAY,EAAE,MAAM,GAAG,IAAI,GAC1B,cAAc,CAAC,UAAU,CAAC,CAc5B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side checksum helpers for download streams.
|
|
3
|
+
*
|
|
4
|
+
* B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file
|
|
5
|
+
* checksum is available. These helpers verify streamed bytes against that
|
|
6
|
+
* header without buffering the full response in memory.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Throws when a computed download SHA-1 does not match the expected value.
|
|
12
|
+
*
|
|
13
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
14
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
15
|
+
*
|
|
16
|
+
* @throws ChecksumMismatchError when the two digests differ.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertDownloadSha1(expectedSha1: string, actualSha1: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Throws when two range responses disagree about the expected whole-file SHA-1.
|
|
21
|
+
*
|
|
22
|
+
* @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.
|
|
23
|
+
* @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.
|
|
24
|
+
*
|
|
25
|
+
* @throws ChecksumMismatchError when the two header states differ.
|
|
26
|
+
*/
|
|
27
|
+
export declare function assertDownloadSha1HeaderAgreement(expectedSha1: string | null, actualSha1: string | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a download stream with whole-body SHA-1 verification.
|
|
30
|
+
*
|
|
31
|
+
* If B2 did not provide a verifiable whole-file SHA-1 (for example,
|
|
32
|
+
* multipart-finished files report `none`), the original stream is returned.
|
|
33
|
+
*
|
|
34
|
+
* @param body - Download response body.
|
|
35
|
+
* @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.
|
|
36
|
+
*
|
|
37
|
+
* @returns A stream that emits the same bytes and errors on checksum mismatch.
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyDownloadStream(body: ReadableStream<Uint8Array>, expectedSha1: string | null): ReadableStream<Uint8Array>;
|
|
40
|
+
//# sourceMappingURL=checksum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../../src/download/checksum.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2BH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAIjF;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,IAAI,CASN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,YAAY,EAAE,MAAM,GAAG,IAAI,GAC1B,cAAc,CAAC,UAAU,CAAC,CAc5B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ChecksumMismatchError } from "../errors/index.js";
|
|
2
|
+
import { IncrementalSha1 } from "../streams/hash.js";
|
|
3
|
+
import { isVerifiableSha1 } from "../util/sha1.js";
|
|
4
|
+
//#region src/download/checksum.ts
|
|
5
|
+
/**
|
|
6
|
+
* Client-side checksum helpers for download streams.
|
|
7
|
+
*
|
|
8
|
+
* B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file
|
|
9
|
+
* checksum is available. These helpers verify streamed bytes against that
|
|
10
|
+
* header without buffering the full response in memory.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Builds the typed error used when downloaded bytes fail SHA-1 verification.
|
|
16
|
+
*
|
|
17
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
18
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
19
|
+
*
|
|
20
|
+
* @returns A typed checksum mismatch error.
|
|
21
|
+
*/
|
|
22
|
+
function createDownloadChecksumMismatchError(expectedSha1, actualSha1) {
|
|
23
|
+
return new ChecksumMismatchError({
|
|
24
|
+
status: 400,
|
|
25
|
+
code: "bad_sha1_checksum",
|
|
26
|
+
message: `Downloaded content SHA-1 mismatch: expected ${expectedSha1.toLowerCase()}, got ${actualSha1.toLowerCase()}`
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Throws when a computed download SHA-1 does not match the expected value.
|
|
31
|
+
*
|
|
32
|
+
* @param expectedSha1 - SHA-1 digest advertised by the download response.
|
|
33
|
+
* @param actualSha1 - SHA-1 digest computed from the downloaded bytes.
|
|
34
|
+
*
|
|
35
|
+
* @throws ChecksumMismatchError when the two digests differ.
|
|
36
|
+
*/
|
|
37
|
+
function assertDownloadSha1(expectedSha1, actualSha1) {
|
|
38
|
+
if (actualSha1.toLowerCase() !== expectedSha1.toLowerCase()) throw createDownloadChecksumMismatchError(expectedSha1, actualSha1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Throws when two range responses disagree about the expected whole-file SHA-1.
|
|
42
|
+
*
|
|
43
|
+
* @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.
|
|
44
|
+
* @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.
|
|
45
|
+
*
|
|
46
|
+
* @throws ChecksumMismatchError when the two header states differ.
|
|
47
|
+
*/
|
|
48
|
+
function assertDownloadSha1HeaderAgreement(expectedSha1, actualSha1) {
|
|
49
|
+
if (expectedSha1 === actualSha1) return;
|
|
50
|
+
throw new ChecksumMismatchError({
|
|
51
|
+
status: 400,
|
|
52
|
+
code: "bad_sha1_checksum",
|
|
53
|
+
message: `Downloaded content SHA-1 header mismatch: expected ${formatSha1ForMessage(expectedSha1)}, got ${formatSha1ForMessage(actualSha1)}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wraps a download stream with whole-body SHA-1 verification.
|
|
58
|
+
*
|
|
59
|
+
* If B2 did not provide a verifiable whole-file SHA-1 (for example,
|
|
60
|
+
* multipart-finished files report `none`), the original stream is returned.
|
|
61
|
+
*
|
|
62
|
+
* @param body - Download response body.
|
|
63
|
+
* @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.
|
|
64
|
+
*
|
|
65
|
+
* @returns A stream that emits the same bytes and errors on checksum mismatch.
|
|
66
|
+
*/
|
|
67
|
+
function verifyDownloadStream(body, expectedSha1) {
|
|
68
|
+
if (!isVerifiableSha1(expectedSha1)) return body;
|
|
69
|
+
const sha1 = new IncrementalSha1();
|
|
70
|
+
const transform = new TransformStream({
|
|
71
|
+
async transform(chunk, controller) {
|
|
72
|
+
await sha1.update(chunk);
|
|
73
|
+
controller.enqueue(chunk);
|
|
74
|
+
},
|
|
75
|
+
async flush() {
|
|
76
|
+
assertDownloadSha1(expectedSha1, await sha1.digest());
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return body.pipeThrough(transform);
|
|
80
|
+
}
|
|
81
|
+
function formatSha1ForMessage(sha1) {
|
|
82
|
+
return sha1 === null ? "missing or unverifiable" : sha1.toLowerCase();
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { assertDownloadSha1, assertDownloadSha1HeaderAgreement, verifyDownloadStream };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=checksum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.js","names":[],"sources":["../../src/download/checksum.ts"],"sourcesContent":["/**\n * Client-side checksum helpers for download streams.\n *\n * B2 sends `X-Bz-Content-Sha1` on download responses when a whole-file\n * checksum is available. These helpers verify streamed bytes against that\n * header without buffering the full response in memory.\n *\n * @packageDocumentation\n */\n\nimport { ChecksumMismatchError } from '../errors/index.ts'\nimport { IncrementalSha1 } from '../streams/hash.ts'\nimport { isVerifiableSha1 } from '../util/sha1.ts'\n\n/**\n * Builds the typed error used when downloaded bytes fail SHA-1 verification.\n *\n * @param expectedSha1 - SHA-1 digest advertised by the download response.\n * @param actualSha1 - SHA-1 digest computed from the downloaded bytes.\n *\n * @returns A typed checksum mismatch error.\n */\nfunction createDownloadChecksumMismatchError(\n expectedSha1: string,\n actualSha1: string,\n): ChecksumMismatchError {\n const expected = expectedSha1.toLowerCase()\n const actual = actualSha1.toLowerCase()\n return new ChecksumMismatchError({\n status: 400,\n code: 'bad_sha1_checksum',\n message: `Downloaded content SHA-1 mismatch: expected ${expected}, got ${actual}`,\n })\n}\n\n/**\n * Throws when a computed download SHA-1 does not match the expected value.\n *\n * @param expectedSha1 - SHA-1 digest advertised by the download response.\n * @param actualSha1 - SHA-1 digest computed from the downloaded bytes.\n *\n * @throws ChecksumMismatchError when the two digests differ.\n */\nexport function assertDownloadSha1(expectedSha1: string, actualSha1: string): void {\n if (actualSha1.toLowerCase() !== expectedSha1.toLowerCase()) {\n throw createDownloadChecksumMismatchError(expectedSha1, actualSha1)\n }\n}\n\n/**\n * Throws when two range responses disagree about the expected whole-file SHA-1.\n *\n * @param expectedSha1 - The first range's verifiable SHA-1, or null when unavailable.\n * @param actualSha1 - The current range's verifiable SHA-1, or null when unavailable.\n *\n * @throws ChecksumMismatchError when the two header states differ.\n */\nexport function assertDownloadSha1HeaderAgreement(\n expectedSha1: string | null,\n actualSha1: string | null,\n): void {\n if (expectedSha1 === actualSha1) return\n const expected = formatSha1ForMessage(expectedSha1)\n const actual = formatSha1ForMessage(actualSha1)\n throw new ChecksumMismatchError({\n status: 400,\n code: 'bad_sha1_checksum',\n message: `Downloaded content SHA-1 header mismatch: expected ${expected}, got ${actual}`,\n })\n}\n\n/**\n * Wraps a download stream with whole-body SHA-1 verification.\n *\n * If B2 did not provide a verifiable whole-file SHA-1 (for example,\n * multipart-finished files report `none`), the original stream is returned.\n *\n * @param body - Download response body.\n * @param expectedSha1 - Normalized SHA-1 header value, or null when unavailable.\n *\n * @returns A stream that emits the same bytes and errors on checksum mismatch.\n */\nexport function verifyDownloadStream(\n body: ReadableStream<Uint8Array>,\n expectedSha1: string | null,\n): ReadableStream<Uint8Array> {\n if (!isVerifiableSha1(expectedSha1)) return body\n\n const sha1 = new IncrementalSha1()\n const transform = new TransformStream<Uint8Array, Uint8Array>({\n async transform(chunk, controller) {\n await sha1.update(chunk)\n controller.enqueue(chunk)\n },\n async flush() {\n assertDownloadSha1(expectedSha1, await sha1.digest())\n },\n })\n return body.pipeThrough(transform)\n}\n\nfunction formatSha1ForMessage(sha1: string | null): string {\n return sha1 === null ? 'missing or unverifiable' : sha1.toLowerCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,oCACP,cACA,YACuB;CAGvB,OAAO,IAAI,sBAAsB;EAC/B,QAAQ;EACR,MAAM;EACN,SAAS,+CALM,aAAa,YAK4B,EAAS,QAJpD,WAAW,YAIiD;CAC3E,CAAC;AACH;;;;;;;;;AAUA,SAAgB,mBAAmB,cAAsB,YAA0B;CACjF,IAAI,WAAW,YAAY,MAAM,aAAa,YAAY,GACxD,MAAM,oCAAoC,cAAc,UAAU;AAEtE;;;;;;;;;AAUA,SAAgB,kCACd,cACA,YACM;CACN,IAAI,iBAAiB,YAAY;CAGjC,MAAM,IAAI,sBAAsB;EAC9B,QAAQ;EACR,MAAM;EACN,SAAS,sDALM,qBAAqB,YAK2B,EAAS,QAJ3D,qBAAqB,UAI8C;CAClF,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,qBACd,MACA,cAC4B;CAC5B,IAAI,CAAC,iBAAiB,YAAY,GAAG,OAAO;CAE5C,MAAM,OAAO,IAAI,gBAAgB;CACjC,MAAM,YAAY,IAAI,gBAAwC;EAC5D,MAAM,UAAU,OAAO,YAAY;GACjC,MAAM,KAAK,OAAO,KAAK;GACvB,WAAW,QAAQ,KAAK;EAC1B;EACA,MAAM,QAAQ;GACZ,mBAAmB,cAAc,MAAM,KAAK,OAAO,CAAC;EACtD;CACF,CAAC;CACD,OAAO,KAAK,YAAY,SAAS;AACnC;AAEA,SAAS,qBAAqB,MAA6B;CACzD,OAAO,SAAS,OAAO,4BAA4B,KAAK,YAAY;AACtE"}
|
|
@@ -1,122 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
1
|
+
const require_errors_index = require("../errors/index.cjs");
|
|
2
|
+
const require_plan_ranges = require("../util/plan-ranges.cjs");
|
|
3
|
+
const require_text_codec = require("../util/text-codec.cjs");
|
|
4
|
+
const require_normalize = require("../util/normalize.cjs");
|
|
5
|
+
const require_hash = require("../streams/hash.cjs");
|
|
6
|
+
const require_sha1 = require("../util/sha1.cjs");
|
|
7
|
+
const require_checksum = require("./checksum.cjs");
|
|
8
|
+
const require_retry = require("../http/retry.cjs");
|
|
9
|
+
const require_collect = require("../streams/collect.cjs");
|
|
10
|
+
//#region src/download/parallel.ts
|
|
11
|
+
/**
|
|
12
|
+
* Creates a readable stream that downloads a file using parallel byte-range requests.
|
|
13
|
+
*
|
|
14
|
+
* The file is split into fixed-size ranges fetched in a **sliding
|
|
15
|
+
* window** keyed off the consumer's read pace. The window size is
|
|
16
|
+
* `concurrency * 2`: up to `concurrency` ranges are in flight at once,
|
|
17
|
+
* plus up to `concurrency` completed-but-not-yet-emitted ranges buffered
|
|
18
|
+
* ahead of the read head. New fetches kick off only when the consumer
|
|
19
|
+
* reads a chunk, so a slow downstream pipe (e.g. a saturated network
|
|
20
|
+
* sink or a `pipeTo` consumer that drains slowly) backpressures into
|
|
21
|
+
* the SDK and bounds peak memory to `(concurrency * 2) * rangeSize`.
|
|
22
|
+
*
|
|
23
|
+
* The previous eager implementation scheduled every range into
|
|
24
|
+
* `Promise.all` up front; a slow head-of-line range could hold the
|
|
25
|
+
* entire file in memory while later ranges finished and waited.
|
|
26
|
+
*
|
|
27
|
+
* @param raw - Low-level B2 API client.
|
|
28
|
+
* @param accountInfo - Authorized account state.
|
|
29
|
+
* @param options - Parallel download parameters (file ID, size, concurrency).
|
|
30
|
+
*
|
|
31
|
+
* @returns A `ReadableStream` that yields file bytes in order.
|
|
32
|
+
*/
|
|
7
33
|
function createParallelDownloadStream(raw, accountInfo, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
});
|
|
34
|
+
const rangeSize = options.rangeSize ?? 10 * 1024 * 1024;
|
|
35
|
+
const concurrency = options.concurrency ?? 4;
|
|
36
|
+
const totalSize = options.totalSize;
|
|
37
|
+
const retryOptions = {
|
|
38
|
+
...require_retry.DEFAULT_RETRY_OPTIONS,
|
|
39
|
+
maxRetries: options.maxRetries ?? 0
|
|
40
|
+
};
|
|
41
|
+
const abort = options.signal;
|
|
42
|
+
const ranges = require_plan_ranges.planRanges(totalSize, rangeSize);
|
|
43
|
+
const windowSize = concurrency * 2;
|
|
44
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
45
|
+
const buffer = /* @__PURE__ */ new Map();
|
|
46
|
+
let assembledSha1 = null;
|
|
47
|
+
let nextToSchedule = 0;
|
|
48
|
+
let nextToEmit = 0;
|
|
49
|
+
let expectedSha1;
|
|
50
|
+
let firstError = null;
|
|
51
|
+
function scheduleNext() {
|
|
52
|
+
while (firstError === null && abort?.aborted !== true && nextToSchedule < ranges.length && inflight.size + buffer.size < windowSize) {
|
|
53
|
+
const range = ranges[nextToSchedule];
|
|
54
|
+
if (range === void 0) break;
|
|
55
|
+
const idx = nextToSchedule;
|
|
56
|
+
nextToSchedule++;
|
|
57
|
+
const task = (async () => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await fetchRangeWithRetry(raw, accountInfo, options.fileId, range.start, range.end, totalSize, retryOptions, abort);
|
|
60
|
+
buffer.set(idx, result);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (firstError === null) firstError = err;
|
|
63
|
+
} finally {
|
|
64
|
+
inflight.delete(idx);
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
inflight.set(idx, task);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return new ReadableStream({
|
|
71
|
+
start(controller) {
|
|
72
|
+
try {
|
|
73
|
+
abort?.throwIfAborted();
|
|
74
|
+
scheduleNext();
|
|
75
|
+
} catch (err) {
|
|
76
|
+
controller.error(err);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async pull(controller) {
|
|
80
|
+
try {
|
|
81
|
+
while (!buffer.has(nextToEmit)) {
|
|
82
|
+
abort?.throwIfAborted();
|
|
83
|
+
if (firstError !== null) throw firstError;
|
|
84
|
+
if (inflight.size === 0) {
|
|
85
|
+
controller.close();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await Promise.race(inflight.values());
|
|
89
|
+
}
|
|
90
|
+
const result = buffer.get(nextToEmit);
|
|
91
|
+
if (result !== void 0) {
|
|
92
|
+
buffer.delete(nextToEmit);
|
|
93
|
+
nextToEmit++;
|
|
94
|
+
const rangeSha1 = require_sha1.normalizeVerifiableSha1(result.contentSha1);
|
|
95
|
+
if (expectedSha1 === void 0) expectedSha1 = rangeSha1;
|
|
96
|
+
else require_checksum.assertDownloadSha1HeaderAgreement(expectedSha1, rangeSha1);
|
|
97
|
+
if (expectedSha1 !== null) {
|
|
98
|
+
assembledSha1 ??= new require_hash.IncrementalSha1();
|
|
99
|
+
await assembledSha1.update(result.data);
|
|
100
|
+
}
|
|
101
|
+
controller.enqueue(result.data);
|
|
102
|
+
}
|
|
103
|
+
scheduleNext();
|
|
104
|
+
if (nextToEmit >= ranges.length && buffer.size === 0 && inflight.size === 0 && firstError === null) {
|
|
105
|
+
if (expectedSha1 !== void 0 && expectedSha1 !== null && assembledSha1 !== null) require_checksum.assertDownloadSha1(expectedSha1, await assembledSha1.digest());
|
|
106
|
+
controller.close();
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
controller.error(err);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
cancel() {
|
|
113
|
+
buffer.clear();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
92
116
|
}
|
|
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
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Fetches a single byte range with bounded retry on transient failures.
|
|
119
|
+
* @param raw - Low-level B2 API client.
|
|
120
|
+
* @param accountInfo - Authorized account state.
|
|
121
|
+
* @param fileId - ID of the file being downloaded.
|
|
122
|
+
* @param start - Inclusive byte offset where the range begins.
|
|
123
|
+
* @param end - Inclusive byte offset where the range ends.
|
|
124
|
+
* @param totalSize - Expected complete file size.
|
|
125
|
+
* @param retryOptions - Retry settings controlling attempts and backoff.
|
|
126
|
+
* @param signal - Optional abort signal that cancels the range and any pending retry.
|
|
127
|
+
*
|
|
128
|
+
* @returns The range's bytes, or throws after exhausting all retry attempts.
|
|
129
|
+
*/
|
|
130
|
+
async function fetchRangeWithRetry(raw, accountInfo, fileId, start, end, totalSize, retryOptions, signal) {
|
|
131
|
+
let lastError;
|
|
132
|
+
for (let attempt = 0; attempt <= retryOptions.maxRetries; attempt++) {
|
|
133
|
+
if (attempt > 0) {
|
|
134
|
+
const retryAfter = lastError instanceof require_errors_index.B2Error && lastError.retryAfter !== void 0 ? lastError.retryAfter : void 0;
|
|
135
|
+
await require_retry.sleep(require_retry.computeBackoff(attempt - 1, retryOptions, retryAfter), signal);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
signal?.throwIfAborted();
|
|
139
|
+
const resp = await raw.downloadFileById(accountInfo.getDownloadUrl(), accountInfo.getAuthToken(), fileId, {
|
|
140
|
+
range: require_plan_ranges.byteRangeHeader(start, end),
|
|
141
|
+
...signal !== void 0 ? { signal } : {}
|
|
142
|
+
});
|
|
143
|
+
if (resp.status < 200 || resp.status >= 300) throw await classifyDownloadResponseError(resp);
|
|
144
|
+
if (!resp.body) throw new Error("Download chunk has no body");
|
|
145
|
+
const data = await require_collect.collectStream(resp.body);
|
|
146
|
+
validateRangeResponse(resp, start, end, totalSize, data.byteLength);
|
|
147
|
+
return {
|
|
148
|
+
data,
|
|
149
|
+
contentSha1: require_normalize.normalizeSha1(resp.headers.get("X-Bz-Content-Sha1"))
|
|
150
|
+
};
|
|
151
|
+
} catch (err) {
|
|
152
|
+
lastError = err;
|
|
153
|
+
if (signal?.aborted) throw err;
|
|
154
|
+
if (err instanceof DOMException && err.name === "AbortError") throw err;
|
|
155
|
+
if (!isRetryableRangeError(err) || attempt === retryOptions.maxRetries) throw err;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error("Range download failed after retries");
|
|
120
159
|
}
|
|
160
|
+
var RangeValidationError = class extends Error {
|
|
161
|
+
retryable = false;
|
|
162
|
+
constructor(message) {
|
|
163
|
+
super(message);
|
|
164
|
+
this.name = "RangeValidationError";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
function validateRangeResponse(response, start, end, totalSize, byteLength) {
|
|
168
|
+
const expectedLength = end - start + 1;
|
|
169
|
+
if (response.status !== 206) throw new RangeValidationError(`Expected HTTP 206 Partial Content for range ${start}-${end}, got ${response.status}`);
|
|
170
|
+
const contentRange = response.headers.get("Content-Range");
|
|
171
|
+
if (contentRange === null) throw new RangeValidationError(`Missing Content-Range for range ${start}-${end}`);
|
|
172
|
+
const match = contentRange.match(/^bytes (\d+)-(\d+)\/(\d+|\*)$/);
|
|
173
|
+
if (match === null) throw new RangeValidationError(`Invalid Content-Range for range ${start}-${end}: ${contentRange}`);
|
|
174
|
+
const actualStart = Number.parseInt(match[1] ?? "", 10);
|
|
175
|
+
const actualEnd = Number.parseInt(match[2] ?? "", 10);
|
|
176
|
+
const actualTotal = match[3] ?? "";
|
|
177
|
+
if (actualStart !== start || actualEnd !== end) throw new RangeValidationError(`Content-Range ${contentRange} does not match requested range ${start}-${end}`);
|
|
178
|
+
if (actualTotal === "*") throw new RangeValidationError(`Content-Range ${contentRange} does not include total size`);
|
|
179
|
+
if (Number.parseInt(actualTotal, 10) !== totalSize) throw new RangeValidationError(`Content-Range ${contentRange} does not match expected total size ${totalSize}`);
|
|
180
|
+
if (byteLength !== expectedLength) throw new RangeValidationError(`Expected ${expectedLength} bytes for range ${start}-${end}, got ${byteLength}`);
|
|
181
|
+
}
|
|
182
|
+
async function classifyDownloadResponseError(response) {
|
|
183
|
+
let errorBody = {
|
|
184
|
+
status: response.status,
|
|
185
|
+
code: "internal_error",
|
|
186
|
+
message: `HTTP ${response.status}`
|
|
187
|
+
};
|
|
188
|
+
if (response.body !== null) {
|
|
189
|
+
const bytes = await require_collect.collectStream(response.body);
|
|
190
|
+
try {
|
|
191
|
+
const parsed = JSON.parse(require_text_codec.utf8Decoder.decode(bytes));
|
|
192
|
+
errorBody = {
|
|
193
|
+
status: response.status,
|
|
194
|
+
code: parsed.code ?? "internal_error",
|
|
195
|
+
message: parsed.message ?? `HTTP ${response.status}`
|
|
196
|
+
};
|
|
197
|
+
} catch {}
|
|
198
|
+
}
|
|
199
|
+
const retryAfterHeader = response.headers.get("Retry-After");
|
|
200
|
+
const retryAfter = retryAfterHeader !== null ? Number.parseInt(retryAfterHeader, 10) : void 0;
|
|
201
|
+
const requestId = response.headers.get("X-Bz-Request-Id") ?? void 0;
|
|
202
|
+
return require_errors_index.classifyError(errorBody, {
|
|
203
|
+
...retryAfter !== void 0 ? { retryAfter } : {},
|
|
204
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function isRetryableRangeError(err) {
|
|
208
|
+
if (err instanceof require_errors_index.B2Error || err instanceof require_errors_index.NetworkError) return err.retryable;
|
|
209
|
+
if (hasRetryableFlag(err)) return err.retryable;
|
|
210
|
+
return err instanceof TypeError;
|
|
211
|
+
}
|
|
212
|
+
function hasRetryableFlag(err) {
|
|
213
|
+
return typeof err === "object" && err !== null && "retryable" in err && typeof err.retryable === "boolean";
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
121
216
|
exports.createParallelDownloadStream = createParallelDownloadStream;
|
|
122
|
-
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=parallel.cjs.map
|