Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

giga

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

giga - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

38

lib/Giga.js

@@ -25,2 +25,6 @@ 'use strict';

const filename = options.filename || uuidV4();
const filePath = path.posix.join(directory, filename);
const result = {
filePath
};

@@ -30,16 +34,4 @@ if (!src)

return new Promise((resolve, reject) => {
const filePath = path.posix.join(directory, filename);
const dst = this.storage.createWriteStream(filePath, options);
const result = {
filePath
};
src
.pipe(dst)
.once('error', reject)
.once('finish', () => {
return resolve(result);
});
});
return this.storage.upload(src, filePath)
.then(() => result);
}

@@ -62,13 +54,11 @@

return new Promise((resolve, reject) => {
const src = this.storage.createReadStream(filePath, options);
const result = {
filePath
};
src.pipe(dst)
.once('error', reject)
.once('finish', () => {
return resolve(result);
const result = { filePath };
return this.storage.download(filePath, options)
.then(src => {
return new Promise((resolve, reject) => {
src.pipe(dst)
.once('error', reject)
.on('finish', () => resolve(result));
});
});
});
}

@@ -75,0 +65,0 @@

{
"name": "giga",
"version": "0.1.2",
"version": "0.2.0",
"description": "Easy streaming upload and download for storages(File System, AWS S3)",

@@ -5,0 +5,0 @@ "license": "MIT",

<div align="center">
<a href="https://github.com/posquit0/node-identif" title="Identif.js">
<img alt="Identif.js" src="http://www.discoveringidentity.com/resources/WindowsLiveWriter_IdentityTrend9IdentityAnalytics_A52A_image3.png" width="240px" />
</a>
<br />
<h1>Identif</h1>
<h1>Giga</h1>
</div>
<p align="center">
A Helper to verify one's identity via personal channels
Storage-agnostic streaming upload/download in Node.js
</p>
<div align="center">
<a href="https://circleci.com/gh/posquit0/node-identif">
<img alt="CircleCI" src="https://circleci.com/gh/posquit0/node-identif.svg?style=shield" />
<a href="https://circleci.com/gh/posquit0/node-giga">
<img alt="CircleCI" src="https://circleci.com/gh/posquit0/node-giga.svg?style=shield" />
</a>
<a href="https://coveralls.io/github/posquit0/node-identif">
<img src="https://coveralls.io/repos/github/posquit0/node-identif/badge.svg" alt='Coverage Status' />
<a href="https://coveralls.io/github/posquit0/node-giga">
<img src="https://coveralls.io/repos/github/posquit0/node-giga/badge.svg" alt='Coverage Status' />
</a>
<a href="https://badge.fury.io/js/identif">
<img alt="npm version" src="https://badge.fury.io/js/identif.svg" />
<a href="https://badge.fury.io/js/giga">
<img alt="npm version" src="https://badge.fury.io/js/giga.svg" />
</a>
<a href="https://www.npmjs.com/package/identif">
<img alt="npm" src="https://img.shields.io/npm/dt/identif.svg" />
<a href="https://www.npmjs.com/package/giga">
<img alt="npm" src="https://img.shields.io/npm/dt/giga.svg" />
</a>
<a href="https://david-dm.org/posquit0/node-identif">
<img alt="npm" src="https://img.shields.io/david/posquit0/node-identif.svg?style=flat-square" />
<a href="https://david-dm.org/posquit0/node-giga">
<img alt="npm" src="https://img.shields.io/david/posquit0/node-giga.svg?style=flat-square" />
</a>

@@ -39,5 +35,5 @@ <a href="https://opensource.org/licenses/mit-license.php">

**Identif** is an abstract helper class to easily implement the identity verification logic via personal channels like SMS, Phone, E-Mail, and more.
**Giga** is an abstract storage class to easily streaming upload and download files to Local File System, AWS S3, and more.
- It was written for use on [**CARPLAT**](https://carplat.co.kr) which is the platform service for the car rental.
- It was written for use on [**OMNIOUS**](http://www.omnious.com) which provides fashion A.I API service.

@@ -49,73 +45,35 @@

# NPM
$ npm install --save identif
$ npm install --save giga
# Yarn
$ yarn add identif
$ yarn add giga
```
### Dependencies
- [**Redis**](https://redis.io): if you use `RedisStore`, the connection to redis server is required.
## Usage
```node
const { Identif, RedisStore } = require('identif');
const fs = require('fs');
const Giga = require('giga');
const S3Storage = require('giga/storages/S3Storage');
const LocalStorage = require('giga/storages/LocalStorage');
// Create an instance of Identif with RedisStore
const identif = new Identif({
store: new RedisStore({
redis: { host: 'my.redis.com', port: 6379 },
ttl: 3 * 60
const storage = new Giga({
storage: new S3Storage({
region: 'ap-northeast-2',
bucket: 'test'
})
});
// Request the verification
const { requestId, code, createdAt } = await identif.request();
/*
Output
{
requestId: 'e89c3600-6ac7-469e-8d7e-e6e7847b346d',
code: '1274',
createdAt: '2017-04-23T14:47:24.173Z'
}
*/
// Respond to the client including `requestId`, `createdAt`
// Send `code` via a personal secure channel like SMS, E-Mail
// Upload file to S3
const { filePath } = await storage.upload(fs.createReadStream('./my-file'));
// Verify the request
const data = await identif.verify(requestId, code);
if (!data) {
// Failed to verify one's identity
} else {
// Verifed one's identity
}
// Download file from S3
const { filePath } = await storage.download(
'hello-world.txt',
fs.createWriteStream('./my-file')
);
```
## API
### Identif([options])
#### Methods
* `request([extra])`
* `verify(requestId, code)`
### MemoryStore()
#### Methods
* `get(key)`
* `set(key, data)`
### RedisStore([options])
#### Methods
* `get(key)`
* `set(key, data)`
## Contributing

@@ -127,3 +85,3 @@

Please use the [issue tracker](https://github.com/posquit0/node-identif/issues) to report any bugs or ask feature requests.
Please use the [issue tracker](https://github.com/posquit0/node-giga/issues) to report any bugs or ask feature requests.

@@ -138,2 +96,2 @@

[MIT](https://github.com/posquit0/node-identif/blob/master/LICENSE) © [Byungjin Park](http://www.posquit0.com)
[MIT](https://github.com/posquit0/node-giga/blob/master/LICENSE) © [Byungjin Park](http://www.posquit0.com)

@@ -5,3 +5,2 @@ 'use strict';

const path = require('path');
const { PassThrough } = require('stream');

@@ -49,33 +48,41 @@

/**
* Create a stream to read the data from
* Create a readable stream to download the data from
*
* @param {string} filePath
* @param {object} options
* @returns {stream}
* @returns {Promise}
*/
createReadStream(filePath, options = {}) {
download(filePath, options = {}) {
const target = path.join(this.root, path.normalize(filePath));
return fs.createReadStream(target, options);
return new Promise((resolve, reject) => {
try {
const src = fs.createReadStream(target, options);
resolve(src);
} catch (err) {
reject(err);
}
});
}
/**
* Create a stream to write the data to
* Upload the data as a readable stream to
*
* @param {stream} src
* @param {string} filePath
* @param {object} options
* @returns {stream}
* @returns {Promise}
*/
createWriteStream(filePath, options = {}) {
upload(src, filePath, options = {}) {
const target = path.join(this.root, path.normalize(filePath));
const writeStream = new PassThrough();
// Ensure the path is exists
mkdirp(path.dirname(target), { mode: 0o755 })
return mkdirp(path.dirname(target), { mode: 0o755 })
.then(() => {
const fileStream = fs.createWriteStream(target, options);
fileStream.once('error', err => writeStream.emit('error', err));
return writeStream.pipe(fileStream);
})
.catch(err => writeStream.emit('error', err));
return writeStream;
const dst = fs.createWriteStream(target, options);
return new Promise((resolve, reject) => {
src.pipe(dst)
.once('error', reject)
.on('finish', resolve);
});
});
}

@@ -82,0 +89,0 @@

'use strict';
const { PassThrough } = require('stream');
const S3 = require('aws-sdk/clients/s3');

@@ -28,9 +27,9 @@

/**
* Create a stream to read the data from
* Create a readable stream to download the data from
*
* @param {string} filePath
* @param {object} options
* @returns {stream}
* @returns {Promise}
*/
createReadStream(filePath, options = {}) {
download(filePath, options = {}) {
const params = Object.assign({

@@ -41,27 +40,25 @@ 'Bucket': this.bucket,

const request = this.client.getObject(params);
const readStream = request.createReadStream();
const src = request.createReadStream();
request.on('error', err => readStream.emit('error', err));
return readStream;
return new Promise((resolve, reject) => {
request.on('error', reject);
return resolve(src);
});
}
/**
* Create a stream to write the data to
* Upload the data as a readable stream to
*
* @param {stream} src
* @param {string} filePath
* @param {object} options
* @returns {stream}
* @returns {Promise}
*/
createWriteStream(filePath, options = {}) {
const writeStream = new PassThrough();
upload(src, filePath, options = {}) {
const params = Object.assign({
'Bucket': this.bucket,
'Key': filePath,
'Body': writeStream
'Body': src
}, options);
this.client.upload(params, err => {
if (err)
writeStream.emit('error', err);
});
return writeStream;
return this.client.upload(params).promise();
}

@@ -74,3 +71,3 @@

* @param {object} options
* @returns {promise}
* @returns {Promise}
*/

@@ -77,0 +74,0 @@ remove(filePath) {

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