@dnax/core 0.45.7 → 0.45.8
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 +1 -1
- package/utils/index.ts +31 -0
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -479,6 +479,37 @@ const file = {
|
|
|
479
479
|
}
|
|
480
480
|
});
|
|
481
481
|
},
|
|
482
|
+
downloadToDisk: async (
|
|
483
|
+
path: string,
|
|
484
|
+
url: string
|
|
485
|
+
): Promise<{
|
|
486
|
+
size: number;
|
|
487
|
+
type: string;
|
|
488
|
+
lastModified: Date;
|
|
489
|
+
original_name: string | undefined;
|
|
490
|
+
name: string | undefined;
|
|
491
|
+
}> => {
|
|
492
|
+
// save to disk
|
|
493
|
+
return new Promise(async (resolve, reject) => {
|
|
494
|
+
try {
|
|
495
|
+
let r = await fetch(url);
|
|
496
|
+
// let data = await r.arrayBuffer();
|
|
497
|
+
await Bun.write(path, r, {
|
|
498
|
+
createPath: true,
|
|
499
|
+
});
|
|
500
|
+
let file = await Bun.file(path);
|
|
501
|
+
resolve({
|
|
502
|
+
original_name: file.name,
|
|
503
|
+
name: file.name,
|
|
504
|
+
lastModified: moment.unix(file.lastModified).toDate(),
|
|
505
|
+
size: file.size,
|
|
506
|
+
type: file.type,
|
|
507
|
+
});
|
|
508
|
+
} catch (err: any) {
|
|
509
|
+
reject(err?.message);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
},
|
|
482
513
|
|
|
483
514
|
deleteFromDisk: async (path: string) => {
|
|
484
515
|
return new Promise(async (resolve, reject) => {
|