diff --git a/lib/clouddrop-upload.js b/lib/clouddrop-upload.js index 76e7ff9..25a08de 100644 --- a/lib/clouddrop-upload.js +++ b/lib/clouddrop-upload.js @@ -159,7 +159,7 @@ class ClouddropUploader { // Reuse a single buffer for all chunks (only the last chunk may be smaller, // in which case we slice a view). Avoids 64× 16 MB allocations on a 1 GB // file — real GC pressure during busy uploads. - const fd = fs.openSync(filePath, 'r'); + const fh = await fs.promises.open(filePath, 'r'); let bytesSent = 0; const reusableBuf = Buffer.allocUnsafe(chunkSize); try { @@ -169,7 +169,7 @@ class ClouddropUploader { const offset = i * chunkSize; const remaining = fileSize - offset; const thisChunkSize = Math.min(chunkSize, remaining); - fs.readSync(fd, reusableBuf, 0, thisChunkSize, offset); + await fh.read(reusableBuf, 0, thisChunkSize, offset); const body = thisChunkSize === chunkSize ? reusableBuf : reusableBuf.subarray(0, thisChunkSize); @@ -194,7 +194,7 @@ class ClouddropUploader { if (progressCb) progressCb(bytesSent, fileSize); } } finally { - try { fs.closeSync(fd); } catch {} + try { await fh.close(); } catch {} } // 3. Complete session — all bytes are already on the server at this point.