@gigadrive/sdk 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1018,11 +1018,15 @@ var sizeOf = (data) => {
1018
1018
  if (data instanceof ArrayBuffer) return data.byteLength;
1019
1019
  throw new Error("Cannot determine upload size. Pass a File, Blob, Buffer, Uint8Array, or ArrayBuffer.");
1020
1020
  };
1021
- var toTusFile = (data) => {
1022
- if (data instanceof Uint8Array) return isNode() ? data : new Blob([data]);
1023
- if (typeof Blob !== "undefined" && data instanceof Blob) return data;
1024
- const bytes = new Uint8Array(data);
1025
- return isNode() ? bytes : new Blob([bytes]);
1021
+ var toTusFile = async (data) => {
1022
+ if (!isNode()) {
1023
+ if (typeof Blob !== "undefined" && data instanceof Blob) return data;
1024
+ const bytes2 = data instanceof Uint8Array ? data : new Uint8Array(data);
1025
+ return new Blob([bytes2]);
1026
+ }
1027
+ const { Buffer } = await import("buffer");
1028
+ const bytes = typeof Blob !== "undefined" && data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data instanceof Uint8Array ? data : new Uint8Array(data);
1029
+ return Buffer.isBuffer(data) ? data : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1026
1030
  };
1027
1031
  var buildChecksums = (input, sha256) => {
1028
1032
  const checksums = { sha256 };
@@ -1043,7 +1047,7 @@ var resolveUploadSource = async (input, options = {}) => {
1043
1047
  const size = input.contentLength ?? sizeOf(input.data);
1044
1048
  const sha256 = input.checksumSha256 ?? (hash ? (await computeChecksums(await toBytes(input.data))).sha256 : "");
1045
1049
  return {
1046
- tusFile: toTusFile(input.data),
1050
+ tusFile: await toTusFile(input.data),
1047
1051
  size,
1048
1052
  contentType,
1049
1053
  checksums: buildChecksums(input, sha256),