trzsz2 1.3.0 → 1.3.2

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.
@@ -5157,7 +5157,7 @@ var Trzsz2 = (function(exports) {
5157
5157
  */
5158
5158
  cleanup() {
5159
5159
  for (const file of this.openedFiles) {
5160
- file.closeFile();
5160
+ void Promise.resolve(file.closeFile()).catch(console.warn);
5161
5161
  }
5162
5162
  }
5163
5163
  /**
@@ -5375,22 +5375,24 @@ var Trzsz2 = (function(exports) {
5375
5375
  * @param timeoutInMilliseconds - The timeout in milliseconds.
5376
5376
  */
5377
5377
  async recvData(binary, escapeCodes, timeoutInMilliseconds) {
5378
- return await Promise.race([
5379
- new Promise(
5380
- (_resolve, reject) => setTimeout(() => {
5381
- this.cleanTimeoutInMilliseconds = 3e3;
5382
- reject(new TrzszError("Receive data timeout"));
5383
- }, timeoutInMilliseconds)
5384
- ),
5385
- (async () => {
5386
- if (!binary) {
5387
- return await this.recvBinary("DATA");
5388
- }
5389
- const size = await this.recvInteger("DATA");
5390
- const data = await this.buffer.readBinary(size);
5391
- return unescapeData(data, escapeCodes);
5392
- })()
5393
- ]);
5378
+ const receive = async () => {
5379
+ if (!binary) return await this.recvBinary("DATA");
5380
+ const size = await this.recvInteger("DATA");
5381
+ return unescapeData(await this.buffer.readBinary(size), escapeCodes);
5382
+ };
5383
+ if (timeoutInMilliseconds <= 0) return await receive();
5384
+ let timer;
5385
+ const timeout = new Promise((_resolve, reject) => {
5386
+ timer = setTimeout(() => {
5387
+ this.cleanTimeoutInMilliseconds = 3e3;
5388
+ reject(new TrzszError("Receive data timeout"));
5389
+ }, timeoutInMilliseconds);
5390
+ });
5391
+ try {
5392
+ return await Promise.race([receive(), timeout]);
5393
+ } finally {
5394
+ clearTimeout(timer);
5395
+ }
5394
5396
  }
5395
5397
  /**
5396
5398
  * Send action.
@@ -5668,9 +5670,6 @@ var Trzsz2 = (function(exports) {
5668
5670
  * @param mtime - The modification time in milliseconds.
5669
5671
  */
5670
5672
  async sendFileMtime(mtime) {
5671
- if (this.transferConfig.mtime !== true) {
5672
- return;
5673
- }
5674
5673
  await this.sendInteger("MTIME", mtime);
5675
5674
  await this.checkInteger(mtime);
5676
5675
  }
@@ -5699,9 +5698,11 @@ var Trzsz2 = (function(exports) {
5699
5698
  const size = file.getSize();
5700
5699
  await this.sendFileSize(size, progressCallback);
5701
5700
  const digest = await this.sendFileData(file, size, binary, escapeCodes, maxBufSize, progressCallback);
5702
- file.closeFile();
5701
+ await file.closeFile();
5703
5702
  await this.sendFileMD5(digest, progressCallback);
5704
- await this.sendFileMtime(file.getMtime());
5703
+ if (this.transferConfig.mtime === true) {
5704
+ await this.sendFileMtime(file.getMtime?.() ?? 0);
5705
+ }
5705
5706
  }
5706
5707
  return remoteNames;
5707
5708
  }
@@ -5850,11 +5851,11 @@ var Trzsz2 = (function(exports) {
5850
5851
  timeoutInMilliseconds,
5851
5852
  progressCallback
5852
5853
  );
5853
- file.closeFile();
5854
+ await file.closeFile();
5854
5855
  await this.recvFileMD5(digest, progressCallback);
5855
5856
  const mtime = await this.recvFileMtime();
5856
5857
  if (mtime > 0) {
5857
- file.setMtime(mtime);
5858
+ file.setMtime?.(mtime);
5858
5859
  }
5859
5860
  }
5860
5861
  return localNames;