backblaze 2.2.0 → 2.3.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/LICENSE +21 -0
- package/index.js +22 -6
- package/package.json +17 -21
- package/readme.md +19 -1
- package/changelog.md +0 -28
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Francisco Presencia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
|
|
|
18
18
|
const b2 = new B2({ applicationKeyId: id, applicationKey: key });
|
|
19
19
|
let bucket = {};
|
|
20
20
|
|
|
21
|
-
const bucketProm =
|
|
21
|
+
const bucketProm = (async () => {
|
|
22
22
|
try {
|
|
23
23
|
const auth = await b2.authorize(); // must authorize first
|
|
24
24
|
const baseURL = auth.data.downloadUrl + "/file/" + name + "/";
|
|
@@ -29,12 +29,12 @@ export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
|
|
|
29
29
|
// const raw = list.data.buckets.find(b => b.bucketName === name);
|
|
30
30
|
|
|
31
31
|
bucket = { ...raw, baseURL };
|
|
32
|
-
|
|
32
|
+
return bucket;
|
|
33
33
|
} catch (error) {
|
|
34
34
|
console.error("AUTH", error.request ? error.request.res : error);
|
|
35
|
-
|
|
35
|
+
throw error;
|
|
36
36
|
}
|
|
37
|
-
});
|
|
37
|
+
})();
|
|
38
38
|
|
|
39
39
|
const info = () => bucketProm;
|
|
40
40
|
|
|
@@ -94,6 +94,22 @@ export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
|
|
|
94
94
|
return Boolean(files.find(file => file.name === remote));
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
const read = async remote => {
|
|
98
|
+
// Allow to pass an object with the full file description
|
|
99
|
+
remote = remote.name || remote;
|
|
100
|
+
remote = remote.replace(/^\//, "");
|
|
101
|
+
|
|
102
|
+
// Ignore any leading slash
|
|
103
|
+
remote = remote.replace(/^\//, "");
|
|
104
|
+
await info();
|
|
105
|
+
const down = await b2.downloadFileByName({
|
|
106
|
+
bucketName: name,
|
|
107
|
+
fileName: remote,
|
|
108
|
+
responseType: "arraybuffer"
|
|
109
|
+
});
|
|
110
|
+
return down.data.toString();
|
|
111
|
+
};
|
|
112
|
+
|
|
97
113
|
const download = async (remote, local) => {
|
|
98
114
|
// Allow to pass an object with the full file description
|
|
99
115
|
remote = remote.name || remote;
|
|
@@ -102,7 +118,7 @@ export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
|
|
|
102
118
|
// Ignore any leading slash
|
|
103
119
|
remote = remote.replace(/^\//, "");
|
|
104
120
|
local = local || "./" + remote;
|
|
105
|
-
|
|
121
|
+
await info();
|
|
106
122
|
const down = await b2.downloadFileByName({
|
|
107
123
|
bucketName: name,
|
|
108
124
|
fileName: remote,
|
|
@@ -158,5 +174,5 @@ export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
|
|
|
158
174
|
return remoteFile;
|
|
159
175
|
};
|
|
160
176
|
|
|
161
|
-
return { info, list, count, exists, upload, download, remove };
|
|
177
|
+
return { info, list, count, exists, upload, read, download, remove };
|
|
162
178
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backblaze",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "An unofficial package to easily deal with Backblaze B2 API",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"type": "module",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"start": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
|
|
12
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
13
|
-
},
|
|
5
|
+
"repository": "github:franciscop/backblaze",
|
|
6
|
+
"author": "Francisco Presencia <public@francisco.io> (https://francisco.io/)",
|
|
7
|
+
"funding": "https://www.paypal.me/franciscopresencia/19",
|
|
8
|
+
"license": "MIT",
|
|
14
9
|
"keywords": [
|
|
15
10
|
"backblaze",
|
|
16
11
|
"b2",
|
|
@@ -18,19 +13,20 @@
|
|
|
18
13
|
"upload",
|
|
19
14
|
"files"
|
|
20
15
|
],
|
|
21
|
-
"
|
|
22
|
-
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "bun test --watch --timeout 30000",
|
|
18
|
+
"test": "bun test --timeout 30000",
|
|
19
|
+
"lint": "oxlint index.js"
|
|
20
|
+
},
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"files": [],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"backblaze-b2": "^1.
|
|
25
|
-
"nanoid": "^
|
|
25
|
+
"backblaze-b2": "^1.7.1",
|
|
26
|
+
"nanoid": "^6.0.2"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"files": [],
|
|
32
|
-
"jest": {
|
|
33
|
-
"transform": {},
|
|
34
|
-
"testEnvironment": "jest-environment-node"
|
|
29
|
+
"@types/bun": "^1.4.4",
|
|
30
|
+
"oxlint": "^1.89.0"
|
|
35
31
|
}
|
|
36
32
|
}
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Backblaze [](https://www.npmjs.com/package/backblaze) [](https://github.com/franciscop/backblaze/actions)
|
|
2
2
|
|
|
3
3
|
An _unofficial_ package to easily deal with Backblaze B2 API on Node.js:
|
|
4
4
|
|
|
@@ -40,6 +40,7 @@ All of the methods are async so they should be used with `await`:
|
|
|
40
40
|
- [`bucket.count()`](#count): display the number of items inside a bucket.
|
|
41
41
|
- [`bucket.upload(local, remote)`](#upload): upload a local file to the bucket.
|
|
42
42
|
- [`bucket.download(remote, local)`](#download): downloads a file from the bucket into the server.
|
|
43
|
+
- [`bucket.read(remote)`](#read): read a file straight away.
|
|
43
44
|
- [`bucket.exists(remote)`](#exists): check whether a file exists on the bucket.
|
|
44
45
|
- [`bucket.remove(remote)`](#remove): delete a file from the bucket.
|
|
45
46
|
|
|
@@ -259,6 +260,23 @@ import { fileURLToPath } from "url";
|
|
|
259
260
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
260
261
|
```
|
|
261
262
|
|
|
263
|
+
### .read()
|
|
264
|
+
|
|
265
|
+
Gets the content of the given file into a variable:
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
bucket.read(remoteFileName) => file data
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The arguments are:
|
|
272
|
+
|
|
273
|
+
- `remoteFileName` (required): the name of the file in the bucket. It can be inside a folder as well. You can pass either a plain string with the name, or [a full File](#file) reference.
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
const raw = await bucket.read("mydata.json");
|
|
277
|
+
const data = JSON.parse(raw);
|
|
278
|
+
```
|
|
279
|
+
|
|
262
280
|
### .exists()
|
|
263
281
|
|
|
264
282
|
Check whether a file exists on the bucket:
|
package/changelog.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
## 2.1.0
|
|
2
|
-
|
|
3
|
-
- [new feature] Added filter prefix to .list(filter).
|
|
4
|
-
- Increased file count for `.list()`.
|
|
5
|
-
- Added workflow testing.
|
|
6
|
-
- [bug] Allow to limit the key to only current bucket, and it still works.
|
|
7
|
-
- [bug] Removed unused Jest
|
|
8
|
-
|
|
9
|
-
### 2.0.2
|
|
10
|
-
|
|
11
|
-
Improved documentation on npm.
|
|
12
|
-
|
|
13
|
-
### 2.0.1
|
|
14
|
-
|
|
15
|
-
Fixed bug where in some situations `.remove()` would return the filename as a string instead of the full File description.
|
|
16
|
-
|
|
17
|
-
## 2.0.0
|
|
18
|
-
|
|
19
|
-
Creted the shared `File` description:
|
|
20
|
-
|
|
21
|
-
- [breaking] `.list()`, `.upload()` and `.remove()` now return the new File description.
|
|
22
|
-
- `.upload()`, `.download()`, `.exists()` and `remove()` now accept either a plain file name or a File description.
|
|
23
|
-
|
|
24
|
-
Added repository info and improved docs.
|
|
25
|
-
|
|
26
|
-
## 1.x.x
|
|
27
|
-
|
|
28
|
-
Created the library. It is built on top of `backblaze-b2` but greatly simplifies how to handle everything.
|