@milaboratories/pl-drivers 1.5.71 → 1.5.72
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/drivers/download_blob/download_blob_task.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/clients/download.ts +2 -2
- package/src/drivers/download_blob/download_blob_task.ts +11 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-drivers",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.72",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20"
|
|
6
6
|
},
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"zod": "~3.23.8",
|
|
33
33
|
"upath": "^2.0.1",
|
|
34
34
|
"@milaboratories/helpers": "^1.6.14",
|
|
35
|
+
"@milaboratories/pl-tree": "^1.6.10",
|
|
36
|
+
"@milaboratories/pl-model-common": "^1.15.5",
|
|
35
37
|
"@milaboratories/ts-helpers": "^1.4.0",
|
|
36
38
|
"@milaboratories/computable": "^2.5.0",
|
|
37
|
-
"@milaboratories/pl-
|
|
38
|
-
"@milaboratories/pl-client": "^2.11.1",
|
|
39
|
-
"@milaboratories/pl-model-common": "^1.15.5"
|
|
39
|
+
"@milaboratories/pl-client": "^2.11.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"eslint": "^9.25.1",
|
package/src/clients/download.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable n/no-unsupported-features/node-builtins */
|
|
2
2
|
import type { GrpcClientProvider, GrpcClientProviderFactory } from '@milaboratories/pl-client';
|
|
3
|
-
import { addRTypeToMetadata } from '@milaboratories/pl-client';
|
|
3
|
+
import { addRTypeToMetadata, stringifyWithResourceId } from '@milaboratories/pl-client';
|
|
4
4
|
import type { ResourceInfo } from '@milaboratories/pl-tree';
|
|
5
5
|
import type { MiLogger } from '@milaboratories/ts-helpers';
|
|
6
6
|
import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
|
|
@@ -55,7 +55,7 @@ export class ClientDownload {
|
|
|
55
55
|
const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, signal);
|
|
56
56
|
|
|
57
57
|
const remoteHeaders = toHeadersMap(headers, fromBytes, toBytes);
|
|
58
|
-
this.logger.info(`download blob from url ${downloadUrl}, headers: ${JSON.stringify(remoteHeaders)}`);
|
|
58
|
+
this.logger.info(`download blob ${stringifyWithResourceId(info)} from url ${downloadUrl}, headers: ${JSON.stringify(remoteHeaders)}`);
|
|
59
59
|
|
|
60
60
|
return isLocal(downloadUrl)
|
|
61
61
|
? await this.readLocalFile(downloadUrl, fromBytes, toBytes)
|
|
@@ -19,6 +19,7 @@ import { Writable } from 'node:stream';
|
|
|
19
19
|
import type { ClientDownload } from '../../clients/download';
|
|
20
20
|
import { UnknownStorageError, WrongLocalFileUrl } from '../../clients/download';
|
|
21
21
|
import { NetworkError400 } from '../../helpers/download';
|
|
22
|
+
import { stringifyWithResourceId } from '@milaboratories/pl-client';
|
|
22
23
|
|
|
23
24
|
/** Downloads a blob and holds callers and watchers for the blob. */
|
|
24
25
|
export class DownloadBlobTask {
|
|
@@ -60,7 +61,7 @@ export class DownloadBlobTask {
|
|
|
60
61
|
this.setDone(size);
|
|
61
62
|
this.change.markChanged();
|
|
62
63
|
} catch (e: any) {
|
|
63
|
-
this.logger.error(`
|
|
64
|
+
this.logger.error(`download blob ${stringifyWithResourceId(this.rInfo)} failed: ${e}, state: ${JSON.stringify(this.state)}`);
|
|
64
65
|
if (nonRecoverableError(e)) {
|
|
65
66
|
this.setError(e);
|
|
66
67
|
this.change.markChanged();
|
|
@@ -73,15 +74,21 @@ export class DownloadBlobTask {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
private async ensureDownloaded() {
|
|
77
|
+
this.signalCtl.signal.throwIfAborted();
|
|
78
|
+
|
|
76
79
|
this.state = {};
|
|
77
80
|
this.state.filePath = this.path;
|
|
78
81
|
await ensureDirExists(path.dirname(this.state.filePath));
|
|
82
|
+
this.signalCtl.signal.throwIfAborted();
|
|
79
83
|
this.state.dirExists = true;
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
const alreadyExists = await fileExists(this.state.filePath);
|
|
86
|
+
this.signalCtl.signal.throwIfAborted();
|
|
87
|
+
if (alreadyExists) {
|
|
82
88
|
this.state.fileExists = true;
|
|
83
89
|
this.logger.info(`a blob was already downloaded: ${this.state.filePath}`);
|
|
84
90
|
const stat = await fsp.stat(this.state.filePath);
|
|
91
|
+
this.signalCtl.signal.throwIfAborted();
|
|
85
92
|
this.state.fileSize = stat.size;
|
|
86
93
|
|
|
87
94
|
return this.state.fileSize;
|
|
@@ -90,14 +97,14 @@ export class DownloadBlobTask {
|
|
|
90
97
|
const { content, size } = await this.clientDownload.downloadBlob(
|
|
91
98
|
this.rInfo,
|
|
92
99
|
{},
|
|
93
|
-
|
|
100
|
+
this.signalCtl.signal,
|
|
94
101
|
);
|
|
95
102
|
this.state.fileSize = size;
|
|
96
103
|
this.state.downloaded = true;
|
|
97
104
|
|
|
98
105
|
await createPathAtomically(this.logger, this.state.filePath, async (fPath: string) => {
|
|
99
106
|
const f = Writable.toWeb(fs.createWriteStream(fPath, { flags: 'wx' }));
|
|
100
|
-
await content.pipeTo(f);
|
|
107
|
+
await content.pipeTo(f, { signal: this.signalCtl.signal });
|
|
101
108
|
this.state.tempWritten = true;
|
|
102
109
|
});
|
|
103
110
|
|