@devbro/neko-storage 0.1.0 → 0.1.1
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/README.md +60 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @devbro/neko-storage
|
|
2
|
+
|
|
3
|
+
a library to abstract file storage and management.
|
|
4
|
+
|
|
5
|
+
## basic usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Storage, StorageFactory } from '@devbro/neko-storage';
|
|
9
|
+
|
|
10
|
+
const storage: Storage = StorageFactory.create(???);
|
|
11
|
+
|
|
12
|
+
// put a file, if file exists already, it will override it.
|
|
13
|
+
content : string | object | Stream | Buffer = ??? ;
|
|
14
|
+
let success = await storage.put('path/to/file/filename.ext', content);
|
|
15
|
+
|
|
16
|
+
// check if the file exists or not
|
|
17
|
+
let file_exists = await storage.exists('path/to/file/filename.ext');
|
|
18
|
+
|
|
19
|
+
// get some details about the file, depending on type of drive metadata may differ
|
|
20
|
+
let file_metadata = await storage.metadata('path/to/file/filename.ext');
|
|
21
|
+
/*
|
|
22
|
+
{
|
|
23
|
+
size: 12345; //bytes
|
|
24
|
+
mimeType: 'application/json';
|
|
25
|
+
lastModifiedDate: 'date string';
|
|
26
|
+
}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// get the file in the format you want, if fails it will throw an Error
|
|
30
|
+
let file_content_as_Json = await storage.getJson('path/to/file/filename.ext');
|
|
31
|
+
let file_content_as_String = await storage.getString('path/to/file/filename.ext');
|
|
32
|
+
let file_content_as_Buffer = await storage.getBuffer('path/to/file/filename.ext');
|
|
33
|
+
let file_content_as_Stream = await storage.getStream('path/to/file/filename.ext');
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// delete a file
|
|
37
|
+
let is_file_deleted = await storage.delete('path/to/file/filename.ext');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## available drivers
|
|
41
|
+
|
|
42
|
+
local
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Storage, StorageFactory } from '@devbro/neko-storage';
|
|
46
|
+
|
|
47
|
+
const basePath = path.resolve(os.tmpdir(), `test-storage-${randomUUID()}`);
|
|
48
|
+
const storage: Storage = StorageFactory.create({ engine: 'local', basePath });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
AWS S3
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { Storage, StorageFactory } from '@devbro/neko-storage';
|
|
55
|
+
|
|
56
|
+
const s3Config : AWSS3Config = ???;
|
|
57
|
+
const storage: Storage = StorageFactory.create({ engine: 's3', { s3Config } });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
More driver available upon request or through PR.
|