@naturalcycles/cloud-storage-lib 1.7.0 → 1.8.0
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/cloudStorage.d.ts +1 -0
- package/dist/cloudStorage.js +5 -0
- package/dist/commonStorage.d.ts +4 -0
- package/dist/inMemoryCommonStorage.d.ts +1 -0
- package/dist/inMemoryCommonStorage.js +5 -0
- package/package.json +1 -1
- package/src/cloudStorage.ts +10 -0
- package/src/commonStorage.ts +5 -0
- package/src/inMemoryCommonStorage.ts +10 -1
package/dist/cloudStorage.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare class CloudStorage implements CommonStorage {
|
|
|
50
50
|
getFileReadStream(bucketName: string, filePath: string): Readable;
|
|
51
51
|
saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void>;
|
|
52
52
|
getFileWriteStream(bucketName: string, filePath: string): Writable;
|
|
53
|
+
uploadFile(localFilePath: string, bucketName: string, bucketFilePath: string): Promise<void>;
|
|
53
54
|
setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>;
|
|
54
55
|
getFileVisibility(bucketName: string, filePath: string): Promise<boolean>;
|
|
55
56
|
copyFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>;
|
package/dist/cloudStorage.js
CHANGED
|
@@ -111,6 +111,11 @@ class CloudStorage {
|
|
|
111
111
|
getFileWriteStream(bucketName, filePath) {
|
|
112
112
|
return this.storage.bucket(bucketName).file(filePath).createWriteStream();
|
|
113
113
|
}
|
|
114
|
+
async uploadFile(localFilePath, bucketName, bucketFilePath) {
|
|
115
|
+
await this.storage.bucket(bucketName).upload(localFilePath, {
|
|
116
|
+
destination: bucketFilePath,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
114
119
|
async setFileVisibility(bucketName, filePath, isPublic) {
|
|
115
120
|
await this.storage.bucket(bucketName).file(filePath)[isPublic ? 'makePublic' : 'makePrivate']();
|
|
116
121
|
}
|
package/dist/commonStorage.d.ts
CHANGED
|
@@ -70,6 +70,10 @@ export interface CommonStorage {
|
|
|
70
70
|
getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<FileEntry>;
|
|
71
71
|
getFileReadStream: (bucketName: string, filePath: string) => Readable;
|
|
72
72
|
getFileWriteStream: (bucketName: string, filePath: string) => Writable;
|
|
73
|
+
/**
|
|
74
|
+
* Upload local file to the bucket (by streaming it).
|
|
75
|
+
*/
|
|
76
|
+
uploadFile: (localFilePath: string, bucketName: string, bucketFilePath: string) => Promise<void>;
|
|
73
77
|
setFileVisibility: (bucketName: string, filePath: string, isPublic: boolean) => Promise<void>;
|
|
74
78
|
getFileVisibility: (bucketName: string, filePath: string) => Promise<boolean>;
|
|
75
79
|
copyFile: (fromBucket: string, fromPath: string, toPath: string, toBucket?: string) => Promise<void>;
|
|
@@ -22,6 +22,7 @@ export declare class InMemoryCommonStorage implements CommonStorage {
|
|
|
22
22
|
getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>;
|
|
23
23
|
getFileReadStream(bucketName: string, filePath: string): Readable;
|
|
24
24
|
getFileWriteStream(_bucketName: string, _filePath: string): Writable;
|
|
25
|
+
uploadFile(localFilePath: string, bucketName: string, bucketFilePath: string): Promise<void>;
|
|
25
26
|
setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>;
|
|
26
27
|
getFileVisibility(bucketName: string, filePath: string): Promise<boolean>;
|
|
27
28
|
copyFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InMemoryCommonStorage = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
7
|
class InMemoryCommonStorage {
|
|
7
8
|
constructor() {
|
|
8
9
|
/**
|
|
@@ -65,6 +66,10 @@ class InMemoryCommonStorage {
|
|
|
65
66
|
getFileWriteStream(_bucketName, _filePath) {
|
|
66
67
|
throw new Error('Method not implemented.');
|
|
67
68
|
}
|
|
69
|
+
async uploadFile(localFilePath, bucketName, bucketFilePath) {
|
|
70
|
+
this.data[bucketName] ||= {};
|
|
71
|
+
this.data[bucketName][bucketFilePath] = await nodejs_lib_1.fs2.readBufferAsync(localFilePath);
|
|
72
|
+
}
|
|
68
73
|
async setFileVisibility(bucketName, filePath, isPublic) {
|
|
69
74
|
this.publicMap[bucketName] ||= {};
|
|
70
75
|
this.publicMap[bucketName][filePath] = isPublic;
|
package/package.json
CHANGED
package/src/cloudStorage.ts
CHANGED
|
@@ -163,6 +163,16 @@ export class CloudStorage implements CommonStorage {
|
|
|
163
163
|
return this.storage.bucket(bucketName).file(filePath).createWriteStream()
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
async uploadFile(
|
|
167
|
+
localFilePath: string,
|
|
168
|
+
bucketName: string,
|
|
169
|
+
bucketFilePath: string,
|
|
170
|
+
): Promise<void> {
|
|
171
|
+
await this.storage.bucket(bucketName).upload(localFilePath, {
|
|
172
|
+
destination: bucketFilePath,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
166
176
|
async setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void> {
|
|
167
177
|
await this.storage.bucket(bucketName).file(filePath)[isPublic ? 'makePublic' : 'makePrivate']()
|
|
168
178
|
}
|
package/src/commonStorage.ts
CHANGED
|
@@ -87,6 +87,11 @@ export interface CommonStorage {
|
|
|
87
87
|
|
|
88
88
|
getFileWriteStream: (bucketName: string, filePath: string) => Writable
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Upload local file to the bucket (by streaming it).
|
|
92
|
+
*/
|
|
93
|
+
uploadFile: (localFilePath: string, bucketName: string, bucketFilePath: string) => Promise<void>
|
|
94
|
+
|
|
90
95
|
setFileVisibility: (bucketName: string, filePath: string, isPublic: boolean) => Promise<void>
|
|
91
96
|
|
|
92
97
|
getFileVisibility: (bucketName: string, filePath: string) => Promise<boolean>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable, Writable } from 'node:stream'
|
|
2
2
|
import { _stringMapEntries, _substringAfterLast, StringMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import { fs2, ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage'
|
|
5
5
|
|
|
6
6
|
export class InMemoryCommonStorage implements CommonStorage {
|
|
@@ -83,6 +83,15 @@ export class InMemoryCommonStorage implements CommonStorage {
|
|
|
83
83
|
throw new Error('Method not implemented.')
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
async uploadFile(
|
|
87
|
+
localFilePath: string,
|
|
88
|
+
bucketName: string,
|
|
89
|
+
bucketFilePath: string,
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
this.data[bucketName] ||= {}
|
|
92
|
+
this.data[bucketName]![bucketFilePath] = await fs2.readBufferAsync(localFilePath)
|
|
93
|
+
}
|
|
94
|
+
|
|
86
95
|
async setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void> {
|
|
87
96
|
this.publicMap[bucketName] ||= {}
|
|
88
97
|
this.publicMap[bucketName]![filePath] = isPublic
|