@backblaze-labs/b2-sdk 0.1.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 +121 -0
- package/LICENSE +21 -0
- package/README.md +664 -0
- package/dist/auth/account-info.d.cts +51 -0
- package/dist/auth/account-info.d.cts.map +1 -0
- package/dist/auth/account-info.d.ts +51 -0
- package/dist/auth/account-info.d.ts.map +1 -0
- package/dist/auth/file.cjs +210 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +157 -0
- package/dist/auth/file.d.cts.map +1 -0
- package/dist/auth/file.d.ts +157 -0
- package/dist/auth/file.d.ts.map +1 -0
- package/dist/auth/file.js +210 -0
- package/dist/auth/file.js.map +1 -0
- package/dist/auth/in-memory.cjs +184 -0
- package/dist/auth/in-memory.cjs.map +1 -0
- package/dist/auth/in-memory.d.cts +147 -0
- package/dist/auth/in-memory.d.cts.map +1 -0
- package/dist/auth/in-memory.d.ts +147 -0
- package/dist/auth/in-memory.d.ts.map +1 -0
- package/dist/auth/in-memory.js +184 -0
- package/dist/auth/in-memory.js.map +1 -0
- package/dist/auth/index.cjs +10 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +6 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/realms.cjs +12 -0
- package/dist/auth/realms.cjs.map +1 -0
- package/dist/auth/realms.d.cts +12 -0
- package/dist/auth/realms.d.cts.map +1 -0
- package/dist/auth/realms.d.ts +12 -0
- package/dist/auth/realms.d.ts.map +1 -0
- package/dist/auth/realms.js +12 -0
- package/dist/auth/realms.js.map +1 -0
- package/dist/auth/upload-url-pool.cjs +52 -0
- package/dist/auth/upload-url-pool.cjs.map +1 -0
- package/dist/auth/upload-url-pool.d.cts +35 -0
- package/dist/auth/upload-url-pool.d.cts.map +1 -0
- package/dist/auth/upload-url-pool.d.ts +35 -0
- package/dist/auth/upload-url-pool.d.ts.map +1 -0
- package/dist/auth/upload-url-pool.js +52 -0
- package/dist/auth/upload-url-pool.js.map +1 -0
- package/dist/bucket.cjs +789 -0
- package/dist/bucket.cjs.map +1 -0
- package/dist/bucket.d.cts +659 -0
- package/dist/bucket.d.cts.map +1 -0
- package/dist/bucket.d.ts +659 -0
- package/dist/bucket.d.ts.map +1 -0
- package/dist/bucket.js +789 -0
- package/dist/bucket.js.map +1 -0
- package/dist/client.cjs +230 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +222 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +222 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +230 -0
- package/dist/client.js.map +1 -0
- package/dist/copy/large.cjs +74 -0
- package/dist/copy/large.cjs.map +1 -0
- package/dist/copy/large.d.cts +53 -0
- package/dist/copy/large.d.cts.map +1 -0
- package/dist/copy/large.d.ts +53 -0
- package/dist/copy/large.d.ts.map +1 -0
- package/dist/copy/large.js +74 -0
- package/dist/copy/large.js.map +1 -0
- package/dist/download/parallel.cjs +122 -0
- package/dist/download/parallel.cjs.map +1 -0
- package/dist/download/parallel.d.cts +42 -0
- package/dist/download/parallel.d.cts.map +1 -0
- package/dist/download/parallel.d.ts +42 -0
- package/dist/download/parallel.d.ts.map +1 -0
- package/dist/download/parallel.js +122 -0
- package/dist/download/parallel.js.map +1 -0
- package/dist/download/single.cjs +117 -0
- package/dist/download/single.cjs.map +1 -0
- package/dist/download/single.d.cts +152 -0
- package/dist/download/single.d.cts.map +1 -0
- package/dist/download/single.d.ts +152 -0
- package/dist/download/single.d.ts.map +1 -0
- package/dist/download/single.js +117 -0
- package/dist/download/single.js.map +1 -0
- package/dist/errors/index.cjs +268 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +264 -0
- package/dist/errors/index.d.cts.map +1 -0
- package/dist/errors/index.d.ts +264 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +268 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/http/retry.cjs +36 -0
- package/dist/http/retry.cjs.map +1 -0
- package/dist/http/retry.d.cts +34 -0
- package/dist/http/retry.d.cts.map +1 -0
- package/dist/http/retry.d.ts +34 -0
- package/dist/http/retry.d.ts.map +1 -0
- package/dist/http/retry.js +36 -0
- package/dist/http/retry.js.map +1 -0
- package/dist/http/transport.cjs +143 -0
- package/dist/http/transport.cjs.map +1 -0
- package/dist/http/transport.d.cts +122 -0
- package/dist/http/transport.d.cts.map +1 -0
- package/dist/http/transport.d.ts +122 -0
- package/dist/http/transport.d.ts.map +1 -0
- package/dist/http/transport.js +143 -0
- package/dist/http/transport.js.map +1 -0
- package/dist/http/url-guard.cjs +97 -0
- package/dist/http/url-guard.cjs.map +1 -0
- package/dist/http/url-guard.d.cts +88 -0
- package/dist/http/url-guard.d.cts.map +1 -0
- package/dist/http/url-guard.d.ts +88 -0
- package/dist/http/url-guard.d.ts.map +1 -0
- package/dist/http/url-guard.js +97 -0
- package/dist/http/url-guard.js.map +1 -0
- package/dist/http/user-agent.cjs +51 -0
- package/dist/http/user-agent.cjs.map +1 -0
- package/dist/http/user-agent.d.cts +28 -0
- package/dist/http/user-agent.d.cts.map +1 -0
- package/dist/http/user-agent.d.ts +28 -0
- package/dist/http/user-agent.d.ts.map +1 -0
- package/dist/http/user-agent.js +51 -0
- package/dist/http/user-agent.js.map +1 -0
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/notifications/index.cjs +7 -0
- package/dist/notifications/index.cjs.map +1 -0
- package/dist/notifications/index.d.cts +3 -0
- package/dist/notifications/index.d.cts.map +1 -0
- package/dist/notifications/index.d.ts +3 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/webhook.cjs +106 -0
- package/dist/notifications/webhook.cjs.map +1 -0
- package/dist/notifications/webhook.d.cts +146 -0
- package/dist/notifications/webhook.d.cts.map +1 -0
- package/dist/notifications/webhook.d.ts +146 -0
- package/dist/notifications/webhook.d.ts.map +1 -0
- package/dist/notifications/webhook.js +106 -0
- package/dist/notifications/webhook.js.map +1 -0
- package/dist/object.cjs +212 -0
- package/dist/object.cjs.map +1 -0
- package/dist/object.d.cts +263 -0
- package/dist/object.d.cts.map +1 -0
- package/dist/object.d.ts +263 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +212 -0
- package/dist/object.js.map +1 -0
- package/dist/package.json.cjs +9 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/package.json.js +9 -0
- package/dist/package.json.js.map +1 -0
- package/dist/raw/encoding.cjs +47 -0
- package/dist/raw/encoding.cjs.map +1 -0
- package/dist/raw/encoding.d.cts +46 -0
- package/dist/raw/encoding.d.cts.map +1 -0
- package/dist/raw/encoding.d.ts +46 -0
- package/dist/raw/encoding.d.ts.map +1 -0
- package/dist/raw/encoding.js +47 -0
- package/dist/raw/encoding.js.map +1 -0
- package/dist/raw/index.cjs +600 -0
- package/dist/raw/index.cjs.map +1 -0
- package/dist/raw/index.d.cts +381 -0
- package/dist/raw/index.d.cts.map +1 -0
- package/dist/raw/index.d.ts +381 -0
- package/dist/raw/index.d.ts.map +1 -0
- package/dist/raw/index.js +601 -0
- package/dist/raw/index.js.map +1 -0
- package/dist/s3/index.cjs +23 -0
- package/dist/s3/index.cjs.map +1 -0
- package/dist/s3/index.d.cts +74 -0
- package/dist/s3/index.d.cts.map +1 -0
- package/dist/s3/index.d.ts +74 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +23 -0
- package/dist/s3/index.js.map +1 -0
- package/dist/simulator/capabilities.cjs +53 -0
- package/dist/simulator/capabilities.cjs.map +1 -0
- package/dist/simulator/capabilities.d.cts +15 -0
- package/dist/simulator/capabilities.d.cts.map +1 -0
- package/dist/simulator/capabilities.d.ts +15 -0
- package/dist/simulator/capabilities.d.ts.map +1 -0
- package/dist/simulator/capabilities.js +53 -0
- package/dist/simulator/capabilities.js.map +1 -0
- package/dist/simulator/index.cjs +1559 -0
- package/dist/simulator/index.cjs.map +1 -0
- package/dist/simulator/index.d.cts +495 -0
- package/dist/simulator/index.d.cts.map +1 -0
- package/dist/simulator/index.d.ts +495 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/simulator/index.js +1560 -0
- package/dist/simulator/index.js.map +1 -0
- package/dist/simulator/validation.cjs +174 -0
- package/dist/simulator/validation.cjs.map +1 -0
- package/dist/simulator/validation.d.cts +104 -0
- package/dist/simulator/validation.d.cts.map +1 -0
- package/dist/simulator/validation.d.ts +104 -0
- package/dist/simulator/validation.d.ts.map +1 -0
- package/dist/simulator/validation.js +174 -0
- package/dist/simulator/validation.js.map +1 -0
- package/dist/streams/collect.cjs +26 -0
- package/dist/streams/collect.cjs.map +1 -0
- package/dist/streams/collect.d.cts +18 -0
- package/dist/streams/collect.d.cts.map +1 -0
- package/dist/streams/collect.d.ts +18 -0
- package/dist/streams/collect.d.ts.map +1 -0
- package/dist/streams/collect.js +26 -0
- package/dist/streams/collect.js.map +1 -0
- package/dist/streams/hash.cjs +123 -0
- package/dist/streams/hash.cjs.map +1 -0
- package/dist/streams/hash.d.cts +42 -0
- package/dist/streams/hash.d.cts.map +1 -0
- package/dist/streams/hash.d.ts +42 -0
- package/dist/streams/hash.d.ts.map +1 -0
- package/dist/streams/hash.js +101 -0
- package/dist/streams/hash.js.map +1 -0
- package/dist/streams/index.cjs +13 -0
- package/dist/streams/index.cjs.map +1 -0
- package/dist/streams/index.d.cts +7 -0
- package/dist/streams/index.d.cts.map +1 -0
- package/dist/streams/index.d.ts +7 -0
- package/dist/streams/index.d.ts.map +1 -0
- package/dist/streams/index.js +13 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams/progress.cjs +47 -0
- package/dist/streams/progress.cjs.map +1 -0
- package/dist/streams/progress.d.cts +53 -0
- package/dist/streams/progress.d.cts.map +1 -0
- package/dist/streams/progress.d.ts +53 -0
- package/dist/streams/progress.d.ts.map +1 -0
- package/dist/streams/progress.js +47 -0
- package/dist/streams/progress.js.map +1 -0
- package/dist/streams/source.cjs +155 -0
- package/dist/streams/source.cjs.map +1 -0
- package/dist/streams/source.d.cts +140 -0
- package/dist/streams/source.d.cts.map +1 -0
- package/dist/streams/source.d.ts +140 -0
- package/dist/streams/source.d.ts.map +1 -0
- package/dist/streams/source.js +155 -0
- package/dist/streams/source.js.map +1 -0
- package/dist/sync/actions/index.cjs +191 -0
- package/dist/sync/actions/index.cjs.map +1 -0
- package/dist/sync/actions/index.d.cts +167 -0
- package/dist/sync/actions/index.d.cts.map +1 -0
- package/dist/sync/actions/index.d.ts +167 -0
- package/dist/sync/actions/index.d.ts.map +1 -0
- package/dist/sync/actions/index.js +191 -0
- package/dist/sync/actions/index.js.map +1 -0
- package/dist/sync/index.cjs +23 -0
- package/dist/sync/index.cjs.map +1 -0
- package/dist/sync/index.d.cts +21 -0
- package/dist/sync/index.d.cts.map +1 -0
- package/dist/sync/index.d.ts +21 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +23 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/pairing.cjs +31 -0
- package/dist/sync/pairing.cjs.map +1 -0
- package/dist/sync/pairing.d.cts +13 -0
- package/dist/sync/pairing.d.cts.map +1 -0
- package/dist/sync/pairing.d.ts +13 -0
- package/dist/sync/pairing.d.ts.map +1 -0
- package/dist/sync/pairing.js +31 -0
- package/dist/sync/pairing.js.map +1 -0
- package/dist/sync/policies/compare.cjs +14 -0
- package/dist/sync/policies/compare.cjs.map +1 -0
- package/dist/sync/policies/compare.d.cts +13 -0
- package/dist/sync/policies/compare.d.cts.map +1 -0
- package/dist/sync/policies/compare.d.ts +13 -0
- package/dist/sync/policies/compare.d.ts.map +1 -0
- package/dist/sync/policies/compare.js +14 -0
- package/dist/sync/policies/compare.js.map +1 -0
- package/dist/sync/policies/index.cjs +74 -0
- package/dist/sync/policies/index.cjs.map +1 -0
- package/dist/sync/policies/index.d.cts +42 -0
- package/dist/sync/policies/index.d.cts.map +1 -0
- package/dist/sync/policies/index.d.ts +42 -0
- package/dist/sync/policies/index.d.ts.map +1 -0
- package/dist/sync/policies/index.js +74 -0
- package/dist/sync/policies/index.js.map +1 -0
- package/dist/sync/scanners/b2.cjs +57 -0
- package/dist/sync/scanners/b2.cjs.map +1 -0
- package/dist/sync/scanners/b2.d.cts +20 -0
- package/dist/sync/scanners/b2.d.cts.map +1 -0
- package/dist/sync/scanners/b2.d.ts +20 -0
- package/dist/sync/scanners/b2.d.ts.map +1 -0
- package/dist/sync/scanners/b2.js +57 -0
- package/dist/sync/scanners/b2.js.map +1 -0
- package/dist/sync/scanners/local.cjs +58 -0
- package/dist/sync/scanners/local.cjs.map +1 -0
- package/dist/sync/scanners/local.d.cts +24 -0
- package/dist/sync/scanners/local.d.cts.map +1 -0
- package/dist/sync/scanners/local.d.ts +24 -0
- package/dist/sync/scanners/local.d.ts.map +1 -0
- package/dist/sync/scanners/local.js +58 -0
- package/dist/sync/scanners/local.js.map +1 -0
- package/dist/sync/synchronizer.cjs +203 -0
- package/dist/sync/synchronizer.cjs.map +1 -0
- package/dist/sync/synchronizer.d.cts +52 -0
- package/dist/sync/synchronizer.d.cts.map +1 -0
- package/dist/sync/synchronizer.d.ts +52 -0
- package/dist/sync/synchronizer.d.ts.map +1 -0
- package/dist/sync/synchronizer.js +181 -0
- package/dist/sync/synchronizer.js.map +1 -0
- package/dist/sync/types.d.cts +121 -0
- package/dist/sync/types.d.cts.map +1 -0
- package/dist/sync/types.d.ts +121 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/types/auth.cjs +58 -0
- package/dist/types/auth.cjs.map +1 -0
- package/dist/types/auth.d.cts +150 -0
- package/dist/types/auth.d.cts.map +1 -0
- package/dist/types/auth.d.ts +150 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +58 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/bucket.cjs +44 -0
- package/dist/types/bucket.cjs.map +1 -0
- package/dist/types/bucket.d.cts +245 -0
- package/dist/types/bucket.d.cts.map +1 -0
- package/dist/types/bucket.d.ts +245 -0
- package/dist/types/bucket.d.ts.map +1 -0
- package/dist/types/bucket.js +44 -0
- package/dist/types/bucket.js.map +1 -0
- package/dist/types/download.d.cts +110 -0
- package/dist/types/download.d.cts.map +1 -0
- package/dist/types/download.d.ts +110 -0
- package/dist/types/download.d.ts.map +1 -0
- package/dist/types/encryption.cjs +343 -0
- package/dist/types/encryption.cjs.map +1 -0
- package/dist/types/encryption.d.cts +132 -0
- package/dist/types/encryption.d.cts.map +1 -0
- package/dist/types/encryption.d.ts +132 -0
- package/dist/types/encryption.d.ts.map +1 -0
- package/dist/types/encryption.js +321 -0
- package/dist/types/encryption.js.map +1 -0
- package/dist/types/errors.d.cts +16 -0
- package/dist/types/errors.d.cts.map +1 -0
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/file.cjs +23 -0
- package/dist/types/file.cjs.map +1 -0
- package/dist/types/file.d.cts +220 -0
- package/dist/types/file.d.cts.map +1 -0
- package/dist/types/file.d.ts +220 -0
- package/dist/types/file.d.ts.map +1 -0
- package/dist/types/file.js +23 -0
- package/dist/types/file.js.map +1 -0
- package/dist/types/ids.cjs +27 -0
- package/dist/types/ids.cjs.map +1 -0
- package/dist/types/ids.d.cts +84 -0
- package/dist/types/ids.d.cts.map +1 -0
- package/dist/types/ids.d.ts +84 -0
- package/dist/types/ids.d.ts.map +1 -0
- package/dist/types/ids.js +27 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/types/index.d.cts +25 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.ts +25 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/key.d.cts +84 -0
- package/dist/types/key.d.cts.map +1 -0
- package/dist/types/key.d.ts +84 -0
- package/dist/types/key.d.ts.map +1 -0
- package/dist/types/lock.cjs +17 -0
- package/dist/types/lock.cjs.map +1 -0
- package/dist/types/lock.d.cts +92 -0
- package/dist/types/lock.d.cts.map +1 -0
- package/dist/types/lock.d.ts +92 -0
- package/dist/types/lock.d.ts.map +1 -0
- package/dist/types/lock.js +17 -0
- package/dist/types/lock.js.map +1 -0
- package/dist/types/notifications.cjs +24 -0
- package/dist/types/notifications.cjs.map +1 -0
- package/dist/types/notifications.d.cts +97 -0
- package/dist/types/notifications.d.cts.map +1 -0
- package/dist/types/notifications.d.ts +97 -0
- package/dist/types/notifications.d.ts.map +1 -0
- package/dist/types/notifications.js +24 -0
- package/dist/types/notifications.js.map +1 -0
- package/dist/types/replication.d.cts +42 -0
- package/dist/types/replication.d.cts.map +1 -0
- package/dist/types/replication.d.ts +42 -0
- package/dist/types/replication.d.ts.map +1 -0
- package/dist/types/upload.d.cts +219 -0
- package/dist/types/upload.d.cts.map +1 -0
- package/dist/types/upload.d.ts +219 -0
- package/dist/types/upload.d.ts.map +1 -0
- package/dist/upload/cancel.cjs +10 -0
- package/dist/upload/cancel.cjs.map +1 -0
- package/dist/upload/cancel.d.cts +23 -0
- package/dist/upload/cancel.d.cts.map +1 -0
- package/dist/upload/cancel.d.ts +23 -0
- package/dist/upload/cancel.d.ts.map +1 -0
- package/dist/upload/cancel.js +10 -0
- package/dist/upload/cancel.js.map +1 -0
- package/dist/upload/concurrency.cjs +54 -0
- package/dist/upload/concurrency.cjs.map +1 -0
- package/dist/upload/concurrency.d.cts +46 -0
- package/dist/upload/concurrency.d.cts.map +1 -0
- package/dist/upload/concurrency.d.ts +46 -0
- package/dist/upload/concurrency.d.ts.map +1 -0
- package/dist/upload/concurrency.js +54 -0
- package/dist/upload/concurrency.js.map +1 -0
- package/dist/upload/large.cjs +222 -0
- package/dist/upload/large.cjs.map +1 -0
- package/dist/upload/large.d.cts +71 -0
- package/dist/upload/large.d.cts.map +1 -0
- package/dist/upload/large.d.ts +71 -0
- package/dist/upload/large.d.ts.map +1 -0
- package/dist/upload/large.js +222 -0
- package/dist/upload/large.js.map +1 -0
- package/dist/upload/resume.cjs +34 -0
- package/dist/upload/resume.cjs.map +1 -0
- package/dist/upload/resume.d.cts +33 -0
- package/dist/upload/resume.d.cts.map +1 -0
- package/dist/upload/resume.d.ts +33 -0
- package/dist/upload/resume.d.ts.map +1 -0
- package/dist/upload/resume.js +34 -0
- package/dist/upload/resume.js.map +1 -0
- package/dist/upload/single.cjs +47 -0
- package/dist/upload/single.cjs.map +1 -0
- package/dist/upload/single.d.cts +51 -0
- package/dist/upload/single.d.cts.map +1 -0
- package/dist/upload/single.d.ts +51 -0
- package/dist/upload/single.d.ts.map +1 -0
- package/dist/upload/single.js +47 -0
- package/dist/upload/single.js.map +1 -0
- package/dist/upload/stream.cjs +198 -0
- package/dist/upload/stream.cjs.map +1 -0
- package/dist/upload/stream.d.cts +61 -0
- package/dist/upload/stream.d.cts.map +1 -0
- package/dist/upload/stream.d.ts +61 -0
- package/dist/upload/stream.d.ts.map +1 -0
- package/dist/upload/stream.js +198 -0
- package/dist/upload/stream.js.map +1 -0
- package/dist/util/best-effort.cjs +10 -0
- package/dist/util/best-effort.cjs.map +1 -0
- package/dist/util/best-effort.d.cts +31 -0
- package/dist/util/best-effort.d.cts.map +1 -0
- package/dist/util/best-effort.d.ts +31 -0
- package/dist/util/best-effort.d.ts.map +1 -0
- package/dist/util/best-effort.js +10 -0
- package/dist/util/best-effort.js.map +1 -0
- package/dist/util/defaults.cjs +11 -0
- package/dist/util/defaults.cjs.map +1 -0
- package/dist/util/defaults.d.cts +54 -0
- package/dist/util/defaults.d.cts.map +1 -0
- package/dist/util/defaults.d.ts +54 -0
- package/dist/util/defaults.d.ts.map +1 -0
- package/dist/util/defaults.js +11 -0
- package/dist/util/defaults.js.map +1 -0
- package/dist/util/normalize.cjs +16 -0
- package/dist/util/normalize.cjs.map +1 -0
- package/dist/util/normalize.d.cts +62 -0
- package/dist/util/normalize.d.cts.map +1 -0
- package/dist/util/normalize.d.ts +62 -0
- package/dist/util/normalize.d.ts.map +1 -0
- package/dist/util/normalize.js +16 -0
- package/dist/util/normalize.js.map +1 -0
- package/dist/util/paginator.cjs +20 -0
- package/dist/util/paginator.cjs.map +1 -0
- package/dist/util/paginator.d.cts +120 -0
- package/dist/util/paginator.d.cts.map +1 -0
- package/dist/util/paginator.d.ts +120 -0
- package/dist/util/paginator.d.ts.map +1 -0
- package/dist/util/paginator.js +20 -0
- package/dist/util/paginator.js.map +1 -0
- package/dist/util/plan-ranges.cjs +28 -0
- package/dist/util/plan-ranges.cjs.map +1 -0
- package/dist/util/plan-ranges.d.cts +56 -0
- package/dist/util/plan-ranges.d.cts.map +1 -0
- package/dist/util/plan-ranges.d.ts +56 -0
- package/dist/util/plan-ranges.d.ts.map +1 -0
- package/dist/util/plan-ranges.js +28 -0
- package/dist/util/plan-ranges.js.map +1 -0
- package/dist/util/text-codec.cjs +7 -0
- package/dist/util/text-codec.cjs.map +1 -0
- package/dist/util/text-codec.d.cts +26 -0
- package/dist/util/text-codec.d.cts.map +1 -0
- package/dist/util/text-codec.d.ts +26 -0
- package/dist/util/text-codec.d.ts.map +1 -0
- package/dist/util/text-codec.js +7 -0
- package/dist/util/text-codec.js.map +1 -0
- package/dist/util/to-error.cjs +7 -0
- package/dist/util/to-error.cjs.map +1 -0
- package/dist/util/to-error.d.cts +15 -0
- package/dist/util/to-error.d.cts.map +1 -0
- package/dist/util/to-error.d.ts +15 -0
- package/dist/util/to-error.d.ts.map +1 -0
- package/dist/util/to-error.js +7 -0
- package/dist/util/to-error.js.map +1 -0
- package/dist/version.cjs +6 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +14 -0
- package/dist/version.d.cts.map +1 -0
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +198 -0
package/dist/object.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { createParallelDownloadStream } from "./download/parallel.js";
|
|
2
|
+
import { downloadByName, headByName, downloadById, headById } from "./download/single.js";
|
|
3
|
+
import { uploadLargeFile } from "./upload/large.js";
|
|
4
|
+
import { uploadSmallFile } from "./upload/single.js";
|
|
5
|
+
import { createWriteStream } from "./upload/stream.js";
|
|
6
|
+
class B2Object {
|
|
7
|
+
/** The file name (path) within the bucket. */
|
|
8
|
+
fileName;
|
|
9
|
+
client;
|
|
10
|
+
bucket;
|
|
11
|
+
/**
|
|
12
|
+
* @param client - The parent B2Client instance.
|
|
13
|
+
* @param bucket - The parent Bucket this object belongs to.
|
|
14
|
+
* @param fileName - The file path within the bucket.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
constructor(client, bucket, fileName) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
this.bucket = bucket;
|
|
21
|
+
this.fileName = fileName;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Uploads data to this file name. Automatically uses multipart upload for large files.
|
|
25
|
+
* @param options - Upload configuration including data source and optional settings.
|
|
26
|
+
*
|
|
27
|
+
* @returns Metadata for the uploaded file version.
|
|
28
|
+
*/
|
|
29
|
+
async upload(options) {
|
|
30
|
+
const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize();
|
|
31
|
+
const isLarge = options.source.size > recommendedPartSize;
|
|
32
|
+
if (isLarge) {
|
|
33
|
+
return uploadLargeFile(this.client.raw, this.client.accountInfo, {
|
|
34
|
+
bucketId: this.bucket.id,
|
|
35
|
+
fileName: this.fileName,
|
|
36
|
+
...options
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const { resume: _resume, resumeFileId: _resumeFileId, ...smallOptions } = options;
|
|
40
|
+
return uploadSmallFile(this.client.raw, this.client.accountInfo, {
|
|
41
|
+
bucketId: this.bucket.id,
|
|
42
|
+
fileName: this.fileName,
|
|
43
|
+
...smallOptions
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Downloads this file by name. Pass `method: 'HEAD'` to fetch only the
|
|
48
|
+
* response headers (file metadata) without streaming the body.
|
|
49
|
+
* @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.
|
|
50
|
+
*
|
|
51
|
+
* @returns The download result with response headers and body stream.
|
|
52
|
+
*/
|
|
53
|
+
async download(options) {
|
|
54
|
+
return downloadByName(this.client.raw, this.client.accountInfo, {
|
|
55
|
+
bucketName: this.bucket.name,
|
|
56
|
+
fileName: this.fileName,
|
|
57
|
+
...options
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Fetches response headers for this file via HTTP HEAD. Returns a
|
|
62
|
+
* body-less result so callers never have to drain the (logically
|
|
63
|
+
* empty) HEAD body themselves.
|
|
64
|
+
*
|
|
65
|
+
* @param options - Optional range, SSE-C decryption, response-header
|
|
66
|
+
* overrides, and abort signal. Same shape as {@link B2Object.download}'s
|
|
67
|
+
* options minus `method` (always HEAD) and `onProgress` (no body).
|
|
68
|
+
*
|
|
69
|
+
* @returns Parsed download headers (content type, SHA-1, file info, etc.).
|
|
70
|
+
*/
|
|
71
|
+
async head(options) {
|
|
72
|
+
return headByName(this.client.raw, this.client.accountInfo, {
|
|
73
|
+
bucketName: this.bucket.name,
|
|
74
|
+
fileName: this.fileName,
|
|
75
|
+
...options
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Downloads a specific version of this file by ID. Pass `method: 'HEAD'`
|
|
80
|
+
* to fetch only the response headers (file metadata) without streaming the body.
|
|
81
|
+
* @param fileId - The file version ID to download.
|
|
82
|
+
* @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.
|
|
83
|
+
*
|
|
84
|
+
* @returns The download result with response headers and body stream.
|
|
85
|
+
*/
|
|
86
|
+
async downloadById(fileId, options) {
|
|
87
|
+
return downloadById(this.client.raw, this.client.accountInfo, {
|
|
88
|
+
fileId,
|
|
89
|
+
...options
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Fetches response headers for a specific version of this file by ID
|
|
94
|
+
* via HTTP HEAD. Returns a body-less result so callers never have to
|
|
95
|
+
* drain the (logically empty) HEAD body themselves.
|
|
96
|
+
*
|
|
97
|
+
* @param fileId - The file version ID to inspect.
|
|
98
|
+
* @param options - Optional range, SSE-C decryption, response-header
|
|
99
|
+
* overrides, and abort signal.
|
|
100
|
+
*
|
|
101
|
+
* @returns Parsed download headers.
|
|
102
|
+
*/
|
|
103
|
+
async headById(fileId, options) {
|
|
104
|
+
return headById(this.client.raw, this.client.accountInfo, {
|
|
105
|
+
fileId,
|
|
106
|
+
...options
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.
|
|
111
|
+
* @param fileId - The file version ID to download.
|
|
112
|
+
* @param totalSize - Total file size in bytes (needed to compute range boundaries).
|
|
113
|
+
* @param options - Concurrency, range size, and abort signal.
|
|
114
|
+
*
|
|
115
|
+
* @returns A Web ReadableStream of file data in sequential order.
|
|
116
|
+
*/
|
|
117
|
+
createReadStream(fileId, totalSize, options) {
|
|
118
|
+
return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {
|
|
119
|
+
fileId,
|
|
120
|
+
totalSize,
|
|
121
|
+
...options
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates a Web `WritableStream` that uploads streamed data into this file
|
|
126
|
+
* using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the
|
|
127
|
+
* returned `writable` and await `done` to get the final {@link FileVersion}.
|
|
128
|
+
*
|
|
129
|
+
* Note: streaming uploads do not support resume because the size and per-part
|
|
130
|
+
* hashes are not known in advance. Use {@link upload} with a buffered source
|
|
131
|
+
* when resume is required.
|
|
132
|
+
*
|
|
133
|
+
* @param options - Streaming upload parameters (part size, concurrency, encryption).
|
|
134
|
+
*
|
|
135
|
+
* @returns A handle with the writable sink and a completion promise.
|
|
136
|
+
*/
|
|
137
|
+
createWriteStream(options) {
|
|
138
|
+
return createWriteStream(this.client.raw, this.client.accountInfo, {
|
|
139
|
+
bucketId: this.bucket.id,
|
|
140
|
+
fileName: this.fileName,
|
|
141
|
+
...options ?? {}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Retrieves metadata for a specific file version.
|
|
146
|
+
* @param fileId - The file version ID to look up.
|
|
147
|
+
*
|
|
148
|
+
* @returns The file version metadata.
|
|
149
|
+
*/
|
|
150
|
+
async getFileInfo(fileId) {
|
|
151
|
+
return this.client.raw.getFileInfo(
|
|
152
|
+
this.client.accountInfo.getApiUrl(),
|
|
153
|
+
this.client.accountInfo.getAuthToken(),
|
|
154
|
+
{ fileId }
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Hides this file by creating a hide marker at this file name.
|
|
159
|
+
*
|
|
160
|
+
* @returns Metadata for the newly created hide marker.
|
|
161
|
+
*/
|
|
162
|
+
async hide() {
|
|
163
|
+
return this.bucket.hideFile(this.fileName);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Permanently deletes a specific version of this file.
|
|
167
|
+
* @param fileId - The unique identifier of the file version to delete.
|
|
168
|
+
*/
|
|
169
|
+
async deleteVersion(fileId) {
|
|
170
|
+
await this.bucket.deleteFileVersion(this.fileName, fileId);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Sets or updates the Object Lock retention policy on a specific file
|
|
174
|
+
* version of this file.
|
|
175
|
+
*
|
|
176
|
+
* The bucket must have Object Lock enabled (`fileLockEnabled: true` at
|
|
177
|
+
* creation time). Governance-mode retention can be shortened or removed
|
|
178
|
+
* by passing `bypassGovernance: true` together with an application key
|
|
179
|
+
* that carries the `bypassGovernance` capability; compliance-mode
|
|
180
|
+
* retention cannot be shortened by anyone until the
|
|
181
|
+
* `retainUntilTimestamp` elapses.
|
|
182
|
+
*
|
|
183
|
+
* @param fileId - The file version to apply the policy to.
|
|
184
|
+
* @param retention - The retention policy to apply.
|
|
185
|
+
* @param options - Optional flag for shortening governance-mode retention.
|
|
186
|
+
*
|
|
187
|
+
* @returns Metadata for the updated file version.
|
|
188
|
+
*/
|
|
189
|
+
async setRetention(fileId, retention, options) {
|
|
190
|
+
return this.bucket.updateFileRetention(this.fileName, fileId, retention, options);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Toggles the legal hold flag on a specific file version of this file.
|
|
194
|
+
*
|
|
195
|
+
* Legal hold is independent of retention: a file can be on legal hold
|
|
196
|
+
* without any retention policy, and vice versa. The bucket must have
|
|
197
|
+
* Object Lock enabled, and any caller must hold the `writeFileLegalHolds`
|
|
198
|
+
* capability.
|
|
199
|
+
*
|
|
200
|
+
* @param fileId - The file version to apply the flag to.
|
|
201
|
+
* @param legalHold - `'on'` to apply the hold, `'off'` to remove it.
|
|
202
|
+
*
|
|
203
|
+
* @returns Metadata for the updated file version.
|
|
204
|
+
*/
|
|
205
|
+
async setLegalHold(fileId, legalHold) {
|
|
206
|
+
return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
B2Object
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sources":["../src/object.ts"],"sourcesContent":["import type { Bucket } from './bucket.ts'\nimport type { B2Client } from './client.ts'\nimport { createParallelDownloadStream } from './download/parallel.ts'\nimport { type DownloadResult, downloadByName } from './download/single.ts'\nimport { type HeadResult, downloadById, headById, headByName } from './download/single.ts'\nimport type { SseCDownloadKey } from './raw/index.ts'\nimport type { ProgressListener } from './streams/progress.ts'\nimport type { ContentSource } from './streams/source.ts'\nimport type { EncryptionSetting } from './types/encryption.ts'\nimport type { FileVersion } from './types/file.ts'\nimport type { FileId, LargeFileId } from './types/ids.ts'\nimport type { FileRetentionValue, LegalHoldValue } from './types/lock.ts'\nimport { uploadLargeFile } from './upload/large.ts'\nimport { uploadSmallFile } from './upload/single.ts'\nimport { type UploadWriteHandle, createWriteStream } from './upload/stream.ts'\n\n/** Options accepted by {@link B2Object.download} and {@link B2Object.downloadById}. */\nexport interface DownloadCallOptions {\n /**\n * HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch only\n * response headers. Prefer the dedicated {@link B2Object.head} /\n * {@link Bucket.head} method over this option — those return a\n * body-less result so callers never have to remember to drain the\n * empty body of a HEAD response.\n */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value (e.g., `\"bytes=0-999\"`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: SseCDownloadKey\n /** Override the response `Content-Disposition` header. */\n readonly b2ContentDisposition?: string\n /** Override the response `Content-Language` header. */\n readonly b2ContentLanguage?: string\n /** Override the response `Content-Encoding` header. */\n readonly b2ContentEncoding?: string\n /** Override the response `Content-Type` header. */\n readonly b2ContentType?: string\n /** Override the response `Cache-Control` header. */\n readonly b2CacheControl?: string\n /** Override the response `Expires` header. */\n readonly b2Expires?: string\n /** Abort signal for cancelling the download. */\n readonly signal?: AbortSignal\n /**\n * Callback invoked as the response body is consumed.\n *\n * Progress is byte-driven, not request-driven: the callback fires per\n * chunk as the caller reads the returned `body` stream, and the final\n * `partsCompleted: 1` event only fires once the stream is read to\n * completion. Downloads that are dropped or aborted partway through\n * will NOT emit a `completePart()` event.\n */\n readonly onProgress?: ProgressListener\n}\n\n/**\n * Options accepted by {@link B2Object.head} / {@link Bucket.head}.\n * Same shape as {@link DownloadCallOptions} minus `method` (always\n * HEAD) and `onProgress` (no body to track).\n */\nexport type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress'>\n\n/**\n * Handle to a specific file (by name) within a B2 bucket.\n *\n * Provides file-scoped upload, download, and management operations.\n * Obtained via {@link Bucket.file}.\n *\n * @example\n * ```ts\n * const obj = bucket.file('photos/2026/sunset.jpg')\n * await obj.upload({ source: new BufferSource(data) })\n * const result = await obj.download()\n * ```\n */\nexport class B2Object {\n /** The file name (path) within the bucket. */\n readonly fileName: string\n private readonly client: B2Client\n private readonly bucket: Bucket\n\n /**\n * @param client - The parent B2Client instance.\n * @param bucket - The parent Bucket this object belongs to.\n * @param fileName - The file path within the bucket.\n *\n * @internal\n */\n constructor(client: B2Client, bucket: Bucket, fileName: string) {\n this.client = client\n this.bucket = bucket\n this.fileName = fileName\n }\n\n /**\n * Uploads data to this file name. Automatically uses multipart upload for large files.\n * @param options - Upload configuration including data source and optional settings.\n *\n * @returns Metadata for the uploaded file version.\n */\n async upload(options: {\n /** Data source to upload. */\n source: ContentSource\n /** MIME type. Defaults to auto-detection by B2. */\n contentType?: string\n /** Custom key-value metadata stored with the file. */\n fileInfo?: Record<string, string>\n /** Server-side encryption settings. */\n serverSideEncryption?: EncryptionSetting\n /** File retention policy (requires file lock). */\n fileRetention?: FileRetentionValue\n /** Legal hold status. */\n legalHold?: LegalHoldValue\n /** Last-modified timestamp in milliseconds since epoch. */\n lastModifiedMillis?: number\n /** Part size override for multipart uploads, in bytes. */\n partSize?: number\n /** Number of concurrent part uploads for large files. */\n concurrency?: number\n /** Callback invoked with upload progress events. */\n onProgress?: ProgressListener\n /** Abort signal for cancelling the upload. */\n signal?: AbortSignal\n /**\n * Resume an unfinished multipart upload for this file name when one\n * exists. Only meaningful on the large-file path. Ignored on the\n * small-file path.\n */\n resume?: boolean\n /**\n * Resume into a specific large-file ID, bypassing discovery.\n * Overrides the `resume` discovery path.\n */\n resumeFileId?: LargeFileId\n }): Promise<FileVersion> {\n const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize()\n const isLarge = options.source.size > recommendedPartSize\n\n if (isLarge) {\n return uploadLargeFile(this.client.raw, this.client.accountInfo, {\n bucketId: this.bucket.id,\n fileName: this.fileName,\n ...options,\n })\n }\n\n // Small-file path doesn't accept resume options.\n const { resume: _resume, resumeFileId: _resumeFileId, ...smallOptions } = options\n return uploadSmallFile(this.client.raw, this.client.accountInfo, {\n bucketId: this.bucket.id,\n fileName: this.fileName,\n ...smallOptions,\n })\n }\n\n /**\n * Downloads this file by name. Pass `method: 'HEAD'` to fetch only the\n * response headers (file metadata) without streaming the body.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async download(options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for this file via HTTP HEAD. Returns a\n * body-less result so callers never have to drain the (logically\n * empty) HEAD body themselves.\n *\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal. Same shape as {@link B2Object.download}'s\n * options minus `method` (always HEAD) and `onProgress` (no body).\n *\n * @returns Parsed download headers (content type, SHA-1, file info, etc.).\n */\n async head(options?: HeadCallOptions): Promise<HeadResult> {\n return headByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Downloads a specific version of this file by ID. Pass `method: 'HEAD'`\n * to fetch only the response headers (file metadata) without streaming the body.\n * @param fileId - The file version ID to download.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async downloadById(fileId: FileId, options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for a specific version of this file by ID\n * via HTTP HEAD. Returns a body-less result so callers never have to\n * drain the (logically empty) HEAD body themselves.\n *\n * @param fileId - The file version ID to inspect.\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal.\n *\n * @returns Parsed download headers.\n */\n async headById(fileId: FileId, options?: HeadCallOptions): Promise<HeadResult> {\n return headById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.\n * @param fileId - The file version ID to download.\n * @param totalSize - Total file size in bytes (needed to compute range boundaries).\n * @param options - Concurrency, range size, and abort signal.\n *\n * @returns A Web ReadableStream of file data in sequential order.\n */\n createReadStream(\n fileId: FileId,\n totalSize: number,\n options?: {\n /** Size of each ranged GET request in bytes. Defaults to 8 MB. */\n rangeSize?: number\n /** Number of concurrent range requests. Defaults to 4. */\n concurrency?: number\n /** Abort signal for cancelling the download. */\n signal?: AbortSignal\n },\n ): ReadableStream<Uint8Array> {\n return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {\n fileId,\n totalSize,\n ...options,\n })\n }\n\n /**\n * Creates a Web `WritableStream` that uploads streamed data into this file\n * using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the\n * returned `writable` and await `done` to get the final {@link FileVersion}.\n *\n * Note: streaming uploads do not support resume because the size and per-part\n * hashes are not known in advance. Use {@link upload} with a buffered source\n * when resume is required.\n *\n * @param options - Streaming upload parameters (part size, concurrency, encryption).\n *\n * @returns A handle with the writable sink and a completion promise.\n */\n createWriteStream(options?: {\n /** MIME type. Defaults to `b2/x-auto`. */\n contentType?: string\n /** Custom key-value metadata stored with the file. */\n fileInfo?: Record<string, string>\n /** Server-side encryption applied to each part. */\n serverSideEncryption?: EncryptionSetting\n /** Target part size in bytes. Defaults to the account's recommended part size. */\n partSize?: number\n /** Maximum number of parts uploaded in parallel. Defaults to 4. */\n concurrency?: number\n /** Callback invoked with upload progress events. */\n onProgress?: ProgressListener\n /** Abort signal that cancels the upload and the unfinished large file. */\n signal?: AbortSignal\n }): UploadWriteHandle {\n return createWriteStream(this.client.raw, this.client.accountInfo, {\n bucketId: this.bucket.id,\n fileName: this.fileName,\n ...(options ?? {}),\n })\n }\n\n /**\n * Retrieves metadata for a specific file version.\n * @param fileId - The file version ID to look up.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(fileId: FileId): Promise<FileVersion> {\n return this.client.raw.getFileInfo(\n this.client.accountInfo.getApiUrl(),\n this.client.accountInfo.getAuthToken(),\n { fileId },\n )\n }\n\n /**\n * Hides this file by creating a hide marker at this file name.\n *\n * @returns Metadata for the newly created hide marker.\n */\n async hide(): Promise<FileVersion> {\n return this.bucket.hideFile(this.fileName)\n }\n\n /**\n * Permanently deletes a specific version of this file.\n * @param fileId - The unique identifier of the file version to delete.\n */\n async deleteVersion(fileId: FileId): Promise<void> {\n await this.bucket.deleteFileVersion(this.fileName, fileId)\n }\n\n /**\n * Sets or updates the Object Lock retention policy on a specific file\n * version of this file.\n *\n * The bucket must have Object Lock enabled (`fileLockEnabled: true` at\n * creation time). Governance-mode retention can be shortened or removed\n * by passing `bypassGovernance: true` together with an application key\n * that carries the `bypassGovernance` capability; compliance-mode\n * retention cannot be shortened by anyone until the\n * `retainUntilTimestamp` elapses.\n *\n * @param fileId - The file version to apply the policy to.\n * @param retention - The retention policy to apply.\n * @param options - Optional flag for shortening governance-mode retention.\n *\n * @returns Metadata for the updated file version.\n */\n async setRetention(\n fileId: FileId,\n retention: FileRetentionValue,\n options?: { bypassGovernance?: boolean },\n ) {\n return this.bucket.updateFileRetention(this.fileName, fileId, retention, options)\n }\n\n /**\n * Toggles the legal hold flag on a specific file version of this file.\n *\n * Legal hold is independent of retention: a file can be on legal hold\n * without any retention policy, and vice versa. The bucket must have\n * Object Lock enabled, and any caller must hold the `writeFileLegalHolds`\n * capability.\n *\n * @param fileId - The file version to apply the flag to.\n * @param legalHold - `'on'` to apply the hold, `'off'` to remove it.\n *\n * @returns Metadata for the updated file version.\n */\n async setLegalHold(fileId: FileId, legalHold: LegalHoldValue) {\n return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold)\n }\n}\n"],"names":[],"mappings":";;;;;AA4EO,MAAM,SAAS;AAAA;AAAA,EAEX;AAAA,EACQ;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASjB,YAAY,QAAkB,QAAgB,UAAkB;AAC9D,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,SAkCY;AACvB,UAAM,sBAAsB,KAAK,OAAO,YAAY,uBAAA;AACpD,UAAM,UAAU,QAAQ,OAAO,OAAO;AAEtC,QAAI,SAAS;AACX,aAAO,gBAAgB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,QAC/D,UAAU,KAAK,OAAO;AAAA,QACtB,UAAU,KAAK;AAAA,QACf,GAAG;AAAA,MAAA,CACJ;AAAA,IACH;AAGA,UAAM,EAAE,QAAQ,SAAS,cAAc,eAAe,GAAG,iBAAiB;AAC1E,WAAO,gBAAgB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MAC/D,UAAU,KAAK,OAAO;AAAA,MACtB,UAAU,KAAK;AAAA,MACf,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,SAAS,SAAwD;AACrE,WAAO,eAAe,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MAC9D,YAAY,KAAK,OAAO;AAAA,MACxB,UAAU,KAAK;AAAA,MACf,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,KAAK,SAAgD;AACzD,WAAO,WAAW,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MAC1D,YAAY,KAAK,OAAO;AAAA,MACxB,UAAU,KAAK;AAAA,MACf,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,aAAa,QAAgB,SAAwD;AACzF,WAAO,aAAa,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MAC5D;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,SAAS,QAAgB,SAAgD;AAC7E,WAAO,SAAS,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MACxD;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,iBACE,QACA,WACA,SAQ4B;AAC5B,WAAO,6BAA6B,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MAC5E;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,kBAAkB,SAeI;AACpB,WAAO,kBAAkB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;AAAA,MACjE,UAAU,KAAK,OAAO;AAAA,MACtB,UAAU,KAAK;AAAA,MACf,GAAI,WAAW,CAAA;AAAA,IAAC,CACjB;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YAAY,QAAsC;AACtD,WAAO,KAAK,OAAO,IAAI;AAAA,MACrB,KAAK,OAAO,YAAY,UAAA;AAAA,MACxB,KAAK,OAAO,YAAY,aAAA;AAAA,MACxB,EAAE,OAAA;AAAA,IAAO;AAAA,EAEb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,OAA6B;AACjC,WAAO,KAAK,OAAO,SAAS,KAAK,QAAQ;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,cAAc,QAA+B;AACjD,UAAM,KAAK,OAAO,kBAAkB,KAAK,UAAU,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,MAAM,aACJ,QACA,WACA,SACA;AACA,WAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,WAAW,OAAO;AAAA,EAClF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,aAAa,QAAgB,WAA2B;AAC5D,WAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,SAAS;AAAA,EACzE;AACF;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const version = "0.1.0";
|
|
4
|
+
const pkg = {
|
|
5
|
+
version
|
|
6
|
+
};
|
|
7
|
+
exports.default = pkg;
|
|
8
|
+
exports.version = version;
|
|
9
|
+
//# sourceMappingURL=package.json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const textCodec = require("../util/text-codec.cjs");
|
|
4
|
+
const SAFE_CHARS = new Set(
|
|
5
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@/".split("")
|
|
6
|
+
);
|
|
7
|
+
function encodeFileName(name) {
|
|
8
|
+
const encoded = [];
|
|
9
|
+
for (const char of name) {
|
|
10
|
+
if (SAFE_CHARS.has(char)) {
|
|
11
|
+
encoded.push(char);
|
|
12
|
+
} else {
|
|
13
|
+
const bytes = textCodec.utf8Encoder.encode(char);
|
|
14
|
+
for (const byte of bytes) {
|
|
15
|
+
encoded.push(`%${byte.toString(16).toUpperCase().padStart(2, "0")}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return encoded.join("");
|
|
20
|
+
}
|
|
21
|
+
function decodeFileName(encoded) {
|
|
22
|
+
return decodeURIComponent(encoded);
|
|
23
|
+
}
|
|
24
|
+
function buildFileInfoHeaders(fileInfo) {
|
|
25
|
+
if (!fileInfo) return {};
|
|
26
|
+
const headers = {};
|
|
27
|
+
for (const [key, value] of Object.entries(fileInfo)) {
|
|
28
|
+
headers[`X-Bz-Info-${encodeFileName(key)}`] = encodeFileName(value);
|
|
29
|
+
}
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
function parseFileInfoHeaders(headers) {
|
|
33
|
+
const info = {};
|
|
34
|
+
headers.forEach((value, key) => {
|
|
35
|
+
const lower = key.toLowerCase();
|
|
36
|
+
if (lower.startsWith("x-bz-info-")) {
|
|
37
|
+
const infoKey = decodeFileName(lower.slice("x-bz-info-".length));
|
|
38
|
+
info[infoKey] = decodeFileName(value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return info;
|
|
42
|
+
}
|
|
43
|
+
exports.buildFileInfoHeaders = buildFileInfoHeaders;
|
|
44
|
+
exports.decodeFileName = decodeFileName;
|
|
45
|
+
exports.encodeFileName = encodeFileName;
|
|
46
|
+
exports.parseFileInfoHeaders = parseFileInfoHeaders;
|
|
47
|
+
//# sourceMappingURL=encoding.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.cjs","sources":["../../src/raw/encoding.ts"],"sourcesContent":["import { utf8Encoder } from '../util/text-codec.ts'\n\n/**\n * Characters that B2 treats as safe (not percent-encoded) in file names.\n *\n * Per the B2 docs, everything except `a-z A-Z 0-9 - . _ ~ / ! $ & ' ( ) * + , ; = : @`\n * must be percent-encoded using UTF-8 byte values.\n */\nconst SAFE_CHARS = new Set(\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@/\".split(''),\n)\n\n/**\n * Percent-encodes a file name using the B2-specific encoding rules.\n *\n * Unlike standard `encodeURIComponent`, B2 keeps `/` and several other\n * characters unencoded while encoding all other non-ASCII and special\n * characters as uppercase percent-encoded UTF-8 bytes.\n *\n * @param name - The raw (unencoded) file name.\n *\n * @returns The percent-encoded file name suitable for `X-Bz-File-Name` headers.\n */\nexport function encodeFileName(name: string): string {\n const encoded: string[] = []\n for (const char of name) {\n if (SAFE_CHARS.has(char)) {\n encoded.push(char)\n } else {\n const bytes = utf8Encoder.encode(char)\n for (const byte of bytes) {\n encoded.push(`%${byte.toString(16).toUpperCase().padStart(2, '0')}`)\n }\n }\n }\n return encoded.join('')\n}\n\n/**\n * Decodes a B2 percent-encoded file name back to a plain string.\n *\n * B2 percent-encoding is compatible with standard `decodeURIComponent`,\n * so this is a thin wrapper.\n *\n * @param encoded - The percent-encoded file name from B2.\n *\n * @returns The decoded file name.\n */\nexport function decodeFileName(encoded: string): string {\n return decodeURIComponent(encoded)\n}\n\n/**\n * Converts a file-info map into `X-Bz-Info-*` HTTP headers.\n *\n * Both keys and values are percent-encoded with {@link encodeFileName}\n * to satisfy B2 header requirements.\n *\n * @param fileInfo - Key/value pairs to attach as custom file info, or `undefined`.\n *\n * @returns A record of header name/value pairs (empty if `fileInfo` is `undefined`).\n */\nexport function buildFileInfoHeaders(\n fileInfo: Record<string, string> | undefined,\n): Record<string, string> {\n if (!fileInfo) return {}\n const headers: Record<string, string> = {}\n for (const [key, value] of Object.entries(fileInfo)) {\n headers[`X-Bz-Info-${encodeFileName(key)}`] = encodeFileName(value)\n }\n return headers\n}\n\n/**\n * Extracts custom file-info key/value pairs from B2 response headers.\n *\n * Scans for headers prefixed with `x-bz-info-` and decodes both the\n * key suffix and value using {@link decodeFileName}.\n *\n * @param headers - The HTTP response headers from a B2 download or file-info call.\n *\n * @returns A record of decoded file-info key/value pairs.\n */\nexport function parseFileInfoHeaders(headers: Headers): Record<string, string> {\n const info: Record<string, string> = {}\n headers.forEach((value, key) => {\n const lower = key.toLowerCase()\n if (lower.startsWith('x-bz-info-')) {\n const infoKey = decodeFileName(lower.slice('x-bz-info-'.length))\n info[infoKey] = decodeFileName(value)\n }\n })\n return info\n}\n"],"names":["utf8Encoder"],"mappings":";;;AAQA,MAAM,aAAa,IAAI;AAAA,EACrB,mFAAmF,MAAM,EAAE;AAC7F;AAaO,SAAS,eAAe,MAAsB;AACnD,QAAM,UAAoB,CAAA;AAC1B,aAAW,QAAQ,MAAM;AACvB,QAAI,WAAW,IAAI,IAAI,GAAG;AACxB,cAAQ,KAAK,IAAI;AAAA,IACnB,OAAO;AACL,YAAM,QAAQA,UAAAA,YAAY,OAAO,IAAI;AACrC,iBAAW,QAAQ,OAAO;AACxB,gBAAQ,KAAK,IAAI,KAAK,SAAS,EAAE,EAAE,YAAA,EAAc,SAAS,GAAG,GAAG,CAAC,EAAE;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACA,SAAO,QAAQ,KAAK,EAAE;AACxB;AAYO,SAAS,eAAe,SAAyB;AACtD,SAAO,mBAAmB,OAAO;AACnC;AAYO,SAAS,qBACd,UACwB;AACxB,MAAI,CAAC,SAAU,QAAO,CAAA;AACtB,QAAM,UAAkC,CAAA;AACxC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACnD,YAAQ,aAAa,eAAe,GAAG,CAAC,EAAE,IAAI,eAAe,KAAK;AAAA,EACpE;AACA,SAAO;AACT;AAYO,SAAS,qBAAqB,SAA0C;AAC7E,QAAM,OAA+B,CAAA;AACrC,UAAQ,QAAQ,CAAC,OAAO,QAAQ;AAC9B,UAAM,QAAQ,IAAI,YAAA;AAClB,QAAI,MAAM,WAAW,YAAY,GAAG;AAClC,YAAM,UAAU,eAAe,MAAM,MAAM,aAAa,MAAM,CAAC;AAC/D,WAAK,OAAO,IAAI,eAAe,KAAK;AAAA,IACtC;AAAA,EACF,CAAC;AACD,SAAO;AACT;;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Percent-encodes a file name using the B2-specific encoding rules.
|
|
3
|
+
*
|
|
4
|
+
* Unlike standard `encodeURIComponent`, B2 keeps `/` and several other
|
|
5
|
+
* characters unencoded while encoding all other non-ASCII and special
|
|
6
|
+
* characters as uppercase percent-encoded UTF-8 bytes.
|
|
7
|
+
*
|
|
8
|
+
* @param name - The raw (unencoded) file name.
|
|
9
|
+
*
|
|
10
|
+
* @returns The percent-encoded file name suitable for `X-Bz-File-Name` headers.
|
|
11
|
+
*/
|
|
12
|
+
export declare function encodeFileName(name: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Decodes a B2 percent-encoded file name back to a plain string.
|
|
15
|
+
*
|
|
16
|
+
* B2 percent-encoding is compatible with standard `decodeURIComponent`,
|
|
17
|
+
* so this is a thin wrapper.
|
|
18
|
+
*
|
|
19
|
+
* @param encoded - The percent-encoded file name from B2.
|
|
20
|
+
*
|
|
21
|
+
* @returns The decoded file name.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeFileName(encoded: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Converts a file-info map into `X-Bz-Info-*` HTTP headers.
|
|
26
|
+
*
|
|
27
|
+
* Both keys and values are percent-encoded with {@link encodeFileName}
|
|
28
|
+
* to satisfy B2 header requirements.
|
|
29
|
+
*
|
|
30
|
+
* @param fileInfo - Key/value pairs to attach as custom file info, or `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* @returns A record of header name/value pairs (empty if `fileInfo` is `undefined`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildFileInfoHeaders(fileInfo: Record<string, string> | undefined): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts custom file-info key/value pairs from B2 response headers.
|
|
37
|
+
*
|
|
38
|
+
* Scans for headers prefixed with `x-bz-info-` and decodes both the
|
|
39
|
+
* key suffix and value using {@link decodeFileName}.
|
|
40
|
+
*
|
|
41
|
+
* @param headers - The HTTP response headers from a B2 download or file-info call.
|
|
42
|
+
*
|
|
43
|
+
* @returns A record of decoded file-info key/value pairs.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseFileInfoHeaders(headers: Headers): Record<string, string>;
|
|
46
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/raw/encoding.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAanD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU7E"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Percent-encodes a file name using the B2-specific encoding rules.
|
|
3
|
+
*
|
|
4
|
+
* Unlike standard `encodeURIComponent`, B2 keeps `/` and several other
|
|
5
|
+
* characters unencoded while encoding all other non-ASCII and special
|
|
6
|
+
* characters as uppercase percent-encoded UTF-8 bytes.
|
|
7
|
+
*
|
|
8
|
+
* @param name - The raw (unencoded) file name.
|
|
9
|
+
*
|
|
10
|
+
* @returns The percent-encoded file name suitable for `X-Bz-File-Name` headers.
|
|
11
|
+
*/
|
|
12
|
+
export declare function encodeFileName(name: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Decodes a B2 percent-encoded file name back to a plain string.
|
|
15
|
+
*
|
|
16
|
+
* B2 percent-encoding is compatible with standard `decodeURIComponent`,
|
|
17
|
+
* so this is a thin wrapper.
|
|
18
|
+
*
|
|
19
|
+
* @param encoded - The percent-encoded file name from B2.
|
|
20
|
+
*
|
|
21
|
+
* @returns The decoded file name.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeFileName(encoded: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Converts a file-info map into `X-Bz-Info-*` HTTP headers.
|
|
26
|
+
*
|
|
27
|
+
* Both keys and values are percent-encoded with {@link encodeFileName}
|
|
28
|
+
* to satisfy B2 header requirements.
|
|
29
|
+
*
|
|
30
|
+
* @param fileInfo - Key/value pairs to attach as custom file info, or `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* @returns A record of header name/value pairs (empty if `fileInfo` is `undefined`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildFileInfoHeaders(fileInfo: Record<string, string> | undefined): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts custom file-info key/value pairs from B2 response headers.
|
|
37
|
+
*
|
|
38
|
+
* Scans for headers prefixed with `x-bz-info-` and decodes both the
|
|
39
|
+
* key suffix and value using {@link decodeFileName}.
|
|
40
|
+
*
|
|
41
|
+
* @param headers - The HTTP response headers from a B2 download or file-info call.
|
|
42
|
+
*
|
|
43
|
+
* @returns A record of decoded file-info key/value pairs.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseFileInfoHeaders(headers: Headers): Record<string, string>;
|
|
46
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/raw/encoding.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAanD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU7E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { utf8Encoder } from "../util/text-codec.js";
|
|
2
|
+
const SAFE_CHARS = new Set(
|
|
3
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@/".split("")
|
|
4
|
+
);
|
|
5
|
+
function encodeFileName(name) {
|
|
6
|
+
const encoded = [];
|
|
7
|
+
for (const char of name) {
|
|
8
|
+
if (SAFE_CHARS.has(char)) {
|
|
9
|
+
encoded.push(char);
|
|
10
|
+
} else {
|
|
11
|
+
const bytes = utf8Encoder.encode(char);
|
|
12
|
+
for (const byte of bytes) {
|
|
13
|
+
encoded.push(`%${byte.toString(16).toUpperCase().padStart(2, "0")}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return encoded.join("");
|
|
18
|
+
}
|
|
19
|
+
function decodeFileName(encoded) {
|
|
20
|
+
return decodeURIComponent(encoded);
|
|
21
|
+
}
|
|
22
|
+
function buildFileInfoHeaders(fileInfo) {
|
|
23
|
+
if (!fileInfo) return {};
|
|
24
|
+
const headers = {};
|
|
25
|
+
for (const [key, value] of Object.entries(fileInfo)) {
|
|
26
|
+
headers[`X-Bz-Info-${encodeFileName(key)}`] = encodeFileName(value);
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
function parseFileInfoHeaders(headers) {
|
|
31
|
+
const info = {};
|
|
32
|
+
headers.forEach((value, key) => {
|
|
33
|
+
const lower = key.toLowerCase();
|
|
34
|
+
if (lower.startsWith("x-bz-info-")) {
|
|
35
|
+
const infoKey = decodeFileName(lower.slice("x-bz-info-".length));
|
|
36
|
+
info[infoKey] = decodeFileName(value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return info;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
buildFileInfoHeaders,
|
|
43
|
+
decodeFileName,
|
|
44
|
+
encodeFileName,
|
|
45
|
+
parseFileInfoHeaders
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sources":["../../src/raw/encoding.ts"],"sourcesContent":["import { utf8Encoder } from '../util/text-codec.ts'\n\n/**\n * Characters that B2 treats as safe (not percent-encoded) in file names.\n *\n * Per the B2 docs, everything except `a-z A-Z 0-9 - . _ ~ / ! $ & ' ( ) * + , ; = : @`\n * must be percent-encoded using UTF-8 byte values.\n */\nconst SAFE_CHARS = new Set(\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@/\".split(''),\n)\n\n/**\n * Percent-encodes a file name using the B2-specific encoding rules.\n *\n * Unlike standard `encodeURIComponent`, B2 keeps `/` and several other\n * characters unencoded while encoding all other non-ASCII and special\n * characters as uppercase percent-encoded UTF-8 bytes.\n *\n * @param name - The raw (unencoded) file name.\n *\n * @returns The percent-encoded file name suitable for `X-Bz-File-Name` headers.\n */\nexport function encodeFileName(name: string): string {\n const encoded: string[] = []\n for (const char of name) {\n if (SAFE_CHARS.has(char)) {\n encoded.push(char)\n } else {\n const bytes = utf8Encoder.encode(char)\n for (const byte of bytes) {\n encoded.push(`%${byte.toString(16).toUpperCase().padStart(2, '0')}`)\n }\n }\n }\n return encoded.join('')\n}\n\n/**\n * Decodes a B2 percent-encoded file name back to a plain string.\n *\n * B2 percent-encoding is compatible with standard `decodeURIComponent`,\n * so this is a thin wrapper.\n *\n * @param encoded - The percent-encoded file name from B2.\n *\n * @returns The decoded file name.\n */\nexport function decodeFileName(encoded: string): string {\n return decodeURIComponent(encoded)\n}\n\n/**\n * Converts a file-info map into `X-Bz-Info-*` HTTP headers.\n *\n * Both keys and values are percent-encoded with {@link encodeFileName}\n * to satisfy B2 header requirements.\n *\n * @param fileInfo - Key/value pairs to attach as custom file info, or `undefined`.\n *\n * @returns A record of header name/value pairs (empty if `fileInfo` is `undefined`).\n */\nexport function buildFileInfoHeaders(\n fileInfo: Record<string, string> | undefined,\n): Record<string, string> {\n if (!fileInfo) return {}\n const headers: Record<string, string> = {}\n for (const [key, value] of Object.entries(fileInfo)) {\n headers[`X-Bz-Info-${encodeFileName(key)}`] = encodeFileName(value)\n }\n return headers\n}\n\n/**\n * Extracts custom file-info key/value pairs from B2 response headers.\n *\n * Scans for headers prefixed with `x-bz-info-` and decodes both the\n * key suffix and value using {@link decodeFileName}.\n *\n * @param headers - The HTTP response headers from a B2 download or file-info call.\n *\n * @returns A record of decoded file-info key/value pairs.\n */\nexport function parseFileInfoHeaders(headers: Headers): Record<string, string> {\n const info: Record<string, string> = {}\n headers.forEach((value, key) => {\n const lower = key.toLowerCase()\n if (lower.startsWith('x-bz-info-')) {\n const infoKey = decodeFileName(lower.slice('x-bz-info-'.length))\n info[infoKey] = decodeFileName(value)\n }\n })\n return info\n}\n"],"names":[],"mappings":";AAQA,MAAM,aAAa,IAAI;AAAA,EACrB,mFAAmF,MAAM,EAAE;AAC7F;AAaO,SAAS,eAAe,MAAsB;AACnD,QAAM,UAAoB,CAAA;AAC1B,aAAW,QAAQ,MAAM;AACvB,QAAI,WAAW,IAAI,IAAI,GAAG;AACxB,cAAQ,KAAK,IAAI;AAAA,IACnB,OAAO;AACL,YAAM,QAAQ,YAAY,OAAO,IAAI;AACrC,iBAAW,QAAQ,OAAO;AACxB,gBAAQ,KAAK,IAAI,KAAK,SAAS,EAAE,EAAE,YAAA,EAAc,SAAS,GAAG,GAAG,CAAC,EAAE;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACA,SAAO,QAAQ,KAAK,EAAE;AACxB;AAYO,SAAS,eAAe,SAAyB;AACtD,SAAO,mBAAmB,OAAO;AACnC;AAYO,SAAS,qBACd,UACwB;AACxB,MAAI,CAAC,SAAU,QAAO,CAAA;AACtB,QAAM,UAAkC,CAAA;AACxC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACnD,YAAQ,aAAa,eAAe,GAAG,CAAC,EAAE,IAAI,eAAe,KAAK;AAAA,EACpE;AACA,SAAO;AACT;AAYO,SAAS,qBAAqB,SAA0C;AAC7E,QAAM,OAA+B,CAAA;AACrC,UAAQ,QAAQ,CAAC,OAAO,QAAQ;AAC9B,UAAM,QAAQ,IAAI,YAAA;AAClB,QAAI,MAAM,WAAW,YAAY,GAAG;AAClC,YAAM,UAAU,eAAe,MAAM,MAAM,aAAa,MAAM,CAAC;AAC/D,WAAK,OAAO,IAAI,eAAe,KAAK;AAAA,IACtC;AAAA,EACF,CAAC;AACD,SAAO;AACT;"}
|