@valentinkolb/filegate 2.3.2 → 2.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentinkolb/filegate",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -86,7 +86,12 @@ const assembleFile = async (meta: UploadMeta): Promise<string | null> => {
86
86
  await semaphore.acquire();
87
87
 
88
88
  try {
89
+ // Check if assembly was already completed by another request while we waited
89
90
  const chunks = await getUploadedChunks(meta.uploadId);
91
+ if (chunks.length === 0) {
92
+ // Chunks were cleaned up - assembly was already completed
93
+ return null;
94
+ }
90
95
  if (chunks.length !== meta.totalChunks) return "missing chunks";
91
96
 
92
97
  // Verify all expected chunk indices are present (0 to totalChunks-1)
@@ -108,12 +113,20 @@ const assembleFile = async (meta: UploadMeta): Promise<string | null> => {
108
113
 
109
114
  try {
110
115
  for (let i = 0; i < meta.totalChunks; i++) {
111
- // Stream each chunk instead of loading entirely into memory
112
- const chunkFile = Bun.file(chunkPath(meta.uploadId, i));
113
- for await (const data of chunkFile.stream()) {
114
- hasher.update(data);
115
- writer.write(data);
116
+ const chunkFilePath = chunkPath(meta.uploadId, i);
117
+ const chunkFile = Bun.file(chunkFilePath);
118
+
119
+ // Verify chunk exists before reading
120
+ if (!(await chunkFile.exists())) {
121
+ writer.end();
122
+ await rm(pathResult.realPath).catch(() => {});
123
+ return `chunk ${i} not found during assembly`;
116
124
  }
125
+
126
+ // Read chunk as buffer (more reliable than streaming)
127
+ const data = new Uint8Array(await chunkFile.arrayBuffer());
128
+ hasher.update(data);
129
+ writer.write(data);
117
130
  }
118
131
  await writer.end();
119
132
  } catch (e) {