Socket
Socket
Sign inDemoInstall

backblaze

Package Overview
Dependencies
9
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.1.0

42

index.js

@@ -17,3 +17,3 @@ import fs from "fs";

export default function (name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
export default function(name, { id = env.B2_ID, key = env.B2_KEY } = {}) {
const b2 = new B2({ applicationKeyId: id, applicationKey: key });

@@ -26,8 +26,12 @@ let bucket = {};

const baseURL = auth.data.downloadUrl + "/file/" + name + "/";
const list = await b2.listBuckets();
const raw = list.data.buckets.find((b) => b.bucketName === name);
const res = await b2.getBucket({ bucketName: name });
const raw = res.data.buckets[0];
// const list = await b2.listBuckets();
// const raw = list.data.buckets.find(b => b.bucketName === name);
bucket = { ...raw, baseURL };
done(bucket);
} catch (error) {
console.error("AUTH", error.request.res);
console.error("AUTH", error.request ? error.request.res : error);
fail(error);

@@ -39,6 +43,10 @@ }

const list = async () => {
const list = async prefix => {
const { bucketId, baseURL } = await info();
const res = await b2.listFileNames({ bucketId });
return res.data.files.map((file) => ({
const res = await b2.listFileNames({
bucketId,
prefix,
maxFileCount: 10000
});
return res.data.files.map(file => ({
name: file.fileName,

@@ -48,3 +56,3 @@ type: file.contentType,

url: baseURL + file.fileName,
timestamp: new Date(file.uploadTimestamp),
timestamp: new Date(file.uploadTimestamp)
}));

@@ -59,3 +67,3 @@ };

const exists = async (file) => {
const exists = async file => {
const files = await list();

@@ -73,3 +81,3 @@ return files.includes(file);

fileName: remote,
responseType: "arraybuffer",
responseType: "arraybuffer"
});

@@ -87,3 +95,3 @@ await writeFile(local, down.data);

b2.getUploadUrl({ bucketId }),
readFile(local),
readFile(local)
]);

@@ -95,3 +103,3 @@ const { authorizationToken, uploadUrl } = res.data;

uploadAuthToken: authorizationToken,
data,
data
});

@@ -103,7 +111,7 @@ return {

url: bucket.baseURL + uploaded.data.fileName,
timestamp: new Date(uploaded.data.uploadTimestamp),
timestamp: new Date(uploaded.data.uploadTimestamp)
};
};
const remove = async (remote) => {
const remove = async remote => {
// Allow to pass an object with the full remote description

@@ -113,6 +121,6 @@ remote = remote.name || remote;

const res = await b2.listFileNames({ bucketId });
const file = res.data.files.find((f) => f.fileName === remote);
const file = res.data.files.find(f => f.fileName === remote);
await b2.deleteFileVersion({
fileId: file.fileId,
fileName: file.fileName,
fileName: file.fileName
});

@@ -124,3 +132,3 @@ return {

url: baseURL + file.fileName,
timestamp: new Date(file.uploadTimestamp),
timestamp: new Date(file.uploadTimestamp)
};

@@ -127,0 +135,0 @@ };

{
"name": "backblaze",
"version": "2.0.2",
"version": "2.1.0",
"description": "An unofficial package to easily deal with Backblaze B2 API",

@@ -27,4 +27,3 @@ "homepage": "https://github.com/franciscop/backblaze#readme",

"devDependencies": {
"dotenv": "^8.2.0",
"jest": "^26.0.1"
"dotenv": "^8.2.0"
},

@@ -31,0 +30,0 @@ "files": [],

# Backblaze
An *unofficial* package to easily deal with Backblaze B2 API on Node.js:
An _unofficial_ package to easily deal with Backblaze B2 API on Node.js:
```js
import Bucket from 'backblaze';
import Bucket from "backblaze";
const bucket = Bucket('bucket-name', {
const bucket = Bucket("bucket-name", {
id: process.env.B2_ID,

@@ -17,6 +17,6 @@ key: process.env.B2_KEY

// Upload a file from a local file to an auto-generated name
const file = await bucket.upload('./avatar.png');
const file = await bucket.upload("./avatar.png");
// Let's download it now as a copy locally
await bucket.download(file, './avatar-copy.png');
await bucket.download(file, "./avatar-copy.png");
```

@@ -33,4 +33,2 @@

## API

@@ -43,3 +41,3 @@

- [`bucket.info()`](#info): load some information related to the bucket itself.
- [`bucket.list()`](#list): show a list with all of the files in your bucket.
- [`bucket.list([prefix])`](#list): show a list with all of the files in your bucket.
- [`bucket.count()`](#count): display the number of items inside a bucket.

@@ -51,4 +49,2 @@ - [`bucket.upload(local, remote)`](#upload): upload a local file to the bucket.

### File

@@ -80,4 +76,2 @@

### Bucket()

@@ -88,4 +82,4 @@

```js
import Bucket from 'backblaze';
const bucket = Bucket('bucket-name', { id, key });
import Bucket from "backblaze";
const bucket = Bucket("bucket-name", { id, key });
// await bucket.upload();

@@ -131,4 +125,2 @@ // await bucket.download();

### .info()

@@ -155,4 +147,2 @@

### .list()

@@ -164,2 +154,3 @@

const list = await bucket.list();
const list = await bucket.list("profile/"); // With a filter
console.log(list);

@@ -178,2 +169,4 @@ // [

You can pass an optional prefix filter, and only those files starting by it will be returned. Use `abc/` to return only the files in folder `abc`.
You might just want to read only e.g. the filenames, so you can `.map()` it with plain Javascript:

@@ -187,4 +180,2 @@

### .count()

@@ -199,4 +190,2 @@

### .upload()

@@ -219,3 +208,3 @@

// Just upload a file and get the path in the response:
const file = await bucket.upload('./avatar.png');
const file = await bucket.upload("./avatar.png");
console.log(file);

@@ -231,9 +220,9 @@ // {

// Upload a file inside a folder and specify the remote name:
await bucket.upload('./public/favicon.png', 'favicon.png');
await bucket.upload("./public/favicon.png", "favicon.png");
// Upload a file to a folder in the bucket:
await bucket.upload('./avatar.png', 'public/favicon.png');
await bucket.upload("./avatar.png", "public/favicon.png");
// Absolute paths:
await bucket.upload(__dirname + '/avatar.png', 'favicon.png')
await bucket.upload(__dirname + "/avatar.png", "favicon.png");
```

@@ -250,4 +239,2 @@

### .download()

@@ -266,16 +253,15 @@

```js
// Upload the file with the same name as locally:
const path = await bucket.download('avatar.png');
console.log(path); // /users/me/projects/backblaze/avatar.png
const path = await bucket.download("avatar.png");
console.log(path); // /users/me/projects/backblaze/avatar.png
// Upload a file inside a folder to the root:
await bucket.download('favicon.png', './public/favicon.png');
await bucket.download("favicon.png", "./public/favicon.png");
// Upload a file to a folder in the bucket:
await bucket.download('public/favicon.png', './avatar.png');
await bucket.download("public/favicon.png", "./avatar.png");
// Absolute paths:
await bucket.download('favicon.png', __dirname + '/avatar.png')
await bucket.download("favicon.png", __dirname + "/avatar.png");
```

@@ -292,6 +278,2 @@

### .exists()

@@ -308,14 +290,12 @@

```js
if (await bucket.exists('avatar.png')) {
console.log('Avatar already exists');
if (await bucket.exists("avatar.png")) {
console.log("Avatar already exists");
}
// Check inside a subfolder
if (await bucket.exists('users/abc.png')) {
console.log('User already has a profile picture');
if (await bucket.exists("users/abc.png")) {
console.log("User already has a profile picture");
}
```
### .remove()

@@ -332,3 +312,3 @@

```js
const file = await bucket.remove('avatar.png');
const file = await bucket.remove("avatar.png");
console.log(file);

@@ -344,5 +324,5 @@ // {

// Remove from inside a subfolder
await bucket.remove('users/abc.png');
await bucket.remove("users/abc.png");
```
It returns the description of the file that was removed.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc