@bytescale/sdk 3.23.1 → 3.24.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.
@@ -1649,7 +1649,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1649
1649
  }, {
1650
1650
  key: "getBaseUrl",
1651
1651
  value: function getBaseUrl(params, prefix) {
1652
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1652
+ var _a, _b;
1653
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1653
1654
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1654
1655
  }
1655
1656
  }, {
@@ -1634,7 +1634,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1634
1634
  }, {
1635
1635
  key: "getBaseUrl",
1636
1636
  value: function getBaseUrl(params, prefix) {
1637
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1637
+ var _a, _b;
1638
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1638
1639
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1639
1640
  }
1640
1641
  }, {
@@ -1649,7 +1649,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1649
1649
  }, {
1650
1650
  key: "getBaseUrl",
1651
1651
  value: function getBaseUrl(params, prefix) {
1652
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1652
+ var _a, _b;
1653
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1653
1654
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1654
1655
  }
1655
1656
  }, {
@@ -1636,7 +1636,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1636
1636
  }, {
1637
1637
  key: "getBaseUrl",
1638
1638
  value: function getBaseUrl(params, prefix) {
1639
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1639
+ var _a, _b;
1640
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1640
1641
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1641
1642
  }
1642
1643
  }, {
@@ -42,6 +42,10 @@ export interface UrlBuilderOptionsBase {
42
42
  * Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
43
43
  */
44
44
  cacheTtl?: number;
45
+ /**
46
+ * The base URL of the Bytescale CDN. (Excludes trailing "/".)
47
+ */
48
+ cdnUrl?: string;
45
49
  /**
46
50
  * Forces the browser to display a download prompt for the file, instead of displaying the file in the browser.
47
51
  *
@@ -1649,7 +1649,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1649
1649
  }, {
1650
1650
  key: "getBaseUrl",
1651
1651
  value: function getBaseUrl(params, prefix) {
1652
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1652
+ var _a, _b;
1653
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1653
1654
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1654
1655
  }
1655
1656
  }, {
@@ -1634,7 +1634,8 @@ var UrlBuilder = /*#__PURE__*/function () {
1634
1634
  }, {
1635
1635
  key: "getBaseUrl",
1636
1636
  value: function getBaseUrl(params, prefix) {
1637
- var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1637
+ var _a, _b;
1638
+ var cdnUrl = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.cdnUrl) !== null && _b !== void 0 ? _b : BytescaleApiClientConfigUtils.defaultCdnUrl;
1638
1639
  return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1639
1640
  }
1640
1641
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.23.1",
3
+ "version": "3.24.0",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -15,10 +15,21 @@ import * as Path from "path";
15
15
  function createRandomStream(sizeInBytes: number): NodeJS.ReadableStream {
16
16
  const dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split("");
17
17
 
18
+ // Ensure the chunk size is small enough to cause enough entropy (as we pick a new character for reach chunk).
19
+ const minRandomBlocks = 10;
20
+ const maxChunkSize = Math.min(64 * 1024, Math.ceil(sizeInBytes / minRandomBlocks));
21
+
18
22
  let producedSize = 0;
19
23
  let iteration = 0;
20
24
  return new Readable({
21
- read(readSize) {
25
+ read(requestedReadSize) {
26
+ const maxRequestedReadSize = Math.min(requestedReadSize, maxChunkSize);
27
+
28
+ // This ensures streams of the same size are unique, else they would have the same contents, assuming chunk size is the same.
29
+ // We use 0.8-1 to prevent really small chunks, which may create inefficiencies.
30
+ const randomness = randomBetween(0.8, 1);
31
+
32
+ let readSize = Math.ceil(maxRequestedReadSize * randomness);
22
33
  let shouldEnd = false;
23
34
 
24
35
  if (producedSize + readSize >= sizeInBytes) {
@@ -48,6 +59,10 @@ function createRandomStream(sizeInBytes: number): NodeJS.ReadableStream {
48
59
  });
49
60
  }
50
61
 
62
+ function randomBetween(min: number, max: number): number {
63
+ return Math.random() * (max - min) + min;
64
+ }
65
+
51
66
  async function writeToDisk(reader: NodeJS.ReadableStream, path: string): Promise<void> {
52
67
  await new Promise((resolve, reject) => {
53
68
  const writer = fs.createWriteStream(path);