Socket
Socket
Sign inDemoInstall

backblaze-b2

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backblaze-b2 - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

9

CHANGELOG.md

@@ -0,1 +1,10 @@

### v1.0.3 (November 30, 2017) - The authorization release
Features
- Add get authorization function [link](https://github.com/yakovkhalinsky/backblaze-b2/pull/37)
Thanks to the contributors for this release
- [Jared Reich](https://github.com/jaredreich)
### v1.0.2 (April 23, 2017) - The fixed buffers release

@@ -2,0 +11,0 @@

@@ -168,2 +168,23 @@ var sha1 = require('sha1');

exports.getDownloadAuthorization = function (b2, args) {
var bucketId = args.bucketId;
var fileNamePrefix = args.fileNamePrefix;
var validDurationInSeconds = args.validDurationInSeconds;
var b2ContentDisposition = args.b2ContentDisposition;
var options = {
url: getDownloadAuthorizationUrl(b2),
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
bucketId: bucketId,
fileNamePrefix: fileNamePrefix,
validDurationInSeconds: validDurationInSeconds,
b2ContentDisposition: b2ContentDisposition
}
};
return request.sendRequest(options);
};
exports.downloadFileByName = function(b2, args) {

@@ -233,2 +254,6 @@ var bucketName = args.bucketName;

function getDownloadAuthorizationUrl(b2) {
return getApiUrl(b2) + '/b2_get_download_authorization';
}
function getDownloadFileByNameUrl(b2, bucketName, fileName) {

@@ -235,0 +260,0 @@ return b2.downloadUrl + '/file/' + bucketName + '/' + fileName;

@@ -74,2 +74,11 @@ var actions = require('./actions');

// args:
// - bucketId
// - fileNamePrefix
// - validDurationInSeconds
// - b2ContentDisposition
B2.prototype.getDownloadAuthorization = function(args) {
return actions.file.getDownloadAuthorization(this, args);
};
// args:
// - bucketName

@@ -76,0 +85,0 @@ // - fileName

10

package.json
{
"name": "backblaze-b2",
"version": "1.0.2",
"version": "1.0.3",
"description": "Node.js Library for the Backblaze B2 Storage Service",

@@ -34,9 +34,9 @@ "main": "index.js",

"expect.js": "^0.3.1",
"mocha": "^3.2.0"
"mocha": "^4.0.1"
},
"dependencies": {
"axios": "^0.16.1",
"q": "^1.4.1",
"sha1": "^1.1.0"
"axios": "^0.17.1",
"q": "^1.5.1",
"sha1": "^1.1.1"
}
}

@@ -5,3 +5,3 @@ ### Backblaze B2 Node.js Library

This library uses promises, so all actions on a `B2` instance return a promise in the following pattern
``` javascript
b2.instanceFunction(arg1, arg2).then(

@@ -11,4 +11,4 @@ successFn(response) { ... },

);
```
### Status of project

@@ -29,3 +29,3 @@

* Updated example in README.md
* Update exiting tests, or add new tests to cover code changes
* Update existing tests, or add new tests to cover code changes

@@ -44,4 +44,78 @@ If you are adding tests, add these to `/test/unit`. Make sure the test is named `fooTest.js` and

### Response Object
Each request returns an object with
status - int, html error Status
statusText
headers
config
request
data - actual returned data from backblaze, https://www.backblaze.com/b2/docs/calling.html
### Basic Example
```javascript
var B2 = require('backblaze-b2');
var b2 = new B2({
accountId: '<accountId>',
applicationKey: 'applicationKey'
});
async function GetBuckets() {
try {
await b2.authorize();
var response = await b2.listBuckets()
console.log(response.data)
} catch (e){
console.log('Error getting buckets:', e)
}
}
```
### Uploading Large Files
To upload large files, you need to split the file into parts (between 5MB and 5GB) and upload each
part seperately
First, you initiate the large file upload to get the fileId
```javascript
var response = await this.b2.startLargeFile({bucketId: bucketID,fileName: fileName })
var fileID = response.data.fileId
```
Then for each part you request an uploadUrl, and use the response to upload the part
```javascript
var response = await this.b2.getUploadPartUrl({fileId: this.fileID})
var uploadURL = resp.data.uploadUrl
var authToken = resp.data.authorizationToken
response = await this.b2.uploadPart({
partNumber: parNum,
uploadUrl: uploadURL,
uploadAuthToken: authToken,
data: buf
})
// status checks etc.
```
Then finish the uploadUrl
```javascript
var response = await this.b2.finishLargeFile({
fileId: this.fileID,
partSha1Array: parts.map(function(buf) {return sha1(buf)})
})
```
### Usage
```javascript
var B2 = require('backblaze-b2');

@@ -85,3 +159,3 @@

mime: '', // optonal mime type, will default to 'b2/x-auto' if not provided
data: 'data' // this is expecting a Buffer not an encoded string,
data: 'data', // this is expecting a Buffer not an encoded string,
info: {

@@ -121,2 +195,10 @@ // optional info headers, prepended with X-Bz-Info- when sent, throws error if more than 10 keys set

// get download authorization
b2.getDownloadAuthorization({
bucketId: 'bucketId',
fileNamePrefix: 'fileNamePrefix',
validDurationInSeconds: 'validDurationInSeconds', // a number from 0 to 604800
b2ContentDisposition: 'b2ContentDisposition'
}); // returns promise
// download file by name

@@ -171,4 +253,4 @@ b2.downloadFileByName({

}) // returns promise
```
### Authors

@@ -175,0 +257,0 @@ * Yakov Khalinsky (@yakovkhalinsky)

@@ -402,2 +402,57 @@ var expect = require('expect.js');

describe('getDownloadAuthorization', function() {
beforeEach(function() {
options = {
bucketId: '123abc',
fileNamePrefix: '/pets',
validDurationInSeconds: 604800,
b2ContentDisposition: 'some content disposition'
};
});
describe('with good response', function() {
beforeEach(function(done) {
response = { foo: '1234' };
file.getDownloadAuthorization(b2, options).then(function(response) {
actualResponse = response;
done();
});
});
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_get_download_authorization',
method: 'POST',
headers:
{
Authorization: 'unicorns and rainbows'
},
data: {
bucketId: '123abc',
fileNamePrefix: '/pets',
validDurationInSeconds: 604800,
b2ContentDisposition: 'some content disposition'
}
});
expect(actualResponse).to.eql(response);
});
});
describe('with error response', function() {
beforeEach(function(done) {
errorMessage = 'Something went wrong';
file.getDownloadAuthorization(b2, options).then(null, function(error) {
actualResponse = error;
done();
});
});
it('Should respond with an error and reject promise', function() {
expect(actualResponse).to.be(errorMessage);
});
});
});
describe('downloadFileByName', function() {

@@ -404,0 +459,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc