@dropgate/core 3.0.5 → 3.0.6

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.js CHANGED
@@ -2342,6 +2342,15 @@ var DropgateClient = class {
2342
2342
  }));
2343
2343
  } else if (serverMeta.files) {
2344
2344
  files = serverMeta.files;
2345
+ if (serverMeta.isEncrypted) {
2346
+ const encryptedChunkSize = this.chunkSize + ENCRYPTION_OVERHEAD_PER_CHUNK;
2347
+ for (const f of files) {
2348
+ if (f.sizeBytes > 0) {
2349
+ const numChunks = Math.ceil(f.sizeBytes / encryptedChunkSize);
2350
+ f.sizeBytes = f.sizeBytes - numChunks * ENCRYPTION_OVERHEAD_PER_CHUNK;
2351
+ }
2352
+ }
2353
+ }
2345
2354
  } else {
2346
2355
  throw new DropgateProtocolError("Invalid bundle metadata: missing files or manifest.");
2347
2356
  }
@@ -3023,7 +3032,14 @@ var DropgateClient = class {
3023
3032
  throw new DropgateNetworkError("Could not fetch file metadata.", { cause: err2 });
3024
3033
  }
3025
3034
  const isEncrypted = Boolean(metadata.isEncrypted);
3026
- const totalBytes = metadata.sizeBytes || 0;
3035
+ const encryptedTotalBytes = metadata.sizeBytes || 0;
3036
+ let totalBytes = encryptedTotalBytes;
3037
+ if (isEncrypted && encryptedTotalBytes > 0) {
3038
+ const downloadChunkSize = Number.isFinite(compat.serverInfo?.capabilities?.upload?.chunkSize) && compat.serverInfo.capabilities.upload.chunkSize > 0 ? compat.serverInfo.capabilities.upload.chunkSize : this.chunkSize;
3039
+ const encryptedChunkSize = downloadChunkSize + ENCRYPTION_OVERHEAD_PER_CHUNK;
3040
+ const numChunks = Math.ceil(encryptedTotalBytes / encryptedChunkSize);
3041
+ totalBytes = encryptedTotalBytes - numChunks * ENCRYPTION_OVERHEAD_PER_CHUNK;
3042
+ }
3027
3043
  if (!onData && totalBytes > MAX_IN_MEMORY_DOWNLOAD_BYTES) {
3028
3044
  const sizeMB = Math.round(totalBytes / (1024 * 1024));
3029
3045
  const limitMB = Math.round(MAX_IN_MEMORY_DOWNLOAD_BYTES / (1024 * 1024));