<commit_before>Storage.js [![Travis-Ci](https://travis-ci.org/keystonejs/storage.js.svg)](https://travis-ci.org/keystonejs/storage.js)&nbsp;[![Code Climate](https://codeclimate.com/github/keystonejs/storage.js/badges/gpa.svg)](https://codeclimate.com/github/keystonejs/storage.js)&nbsp;[![Test Coverage](https://codeclimate.com/github/keystonejs/storage.js/badges/coverage.svg?v=2)](https://codeclimate.com/github/keystonejs/storage.js)&nbsp;[![Dependency Status](https://gemnasium.com/keystonejs/storage.js.svg)](https://gemnasium.com/keystonejs/storage.js)
==========

Storage.js is a NodeJS library that standarizes common available via `npm` libraries like `pkgcloud` and abstracts away differences (especially within callbacks). Just write a simple implementation and leave configuration up to your users.

* Available storage providers:
	* Rackspace
	* Amazon
	* Azure
	* Openshift
	* HP
	* Local disk
	* MongoDB

* To be included soon:
	* Dropbox, Google Drive
	* You tell me :)

* After initial release
	* (S)FTP - due to lack of nice, up-to-date modules, this is for now on hold.

> More providers will be added upon community requests (feel free to create an issue).

## Installation

*Note: Work in progress*. Although it's still work in progress, feel free to fork or do the custom install via `npm`. Further details will be published soon.

## Configuration

After requiring for the first time, invoke either `init` or `add` method by passing configuration object.

```js
var Storage = require('storage');

// #1 option
Storage.init({
	myProvider: {
		provider: Storage.Providers.AmazonS3
		container: '',
		key: '',
		keyId: ''
	},
	// other providers you need in your app
	{...}
});

// #2 option
Storage.add('myProvider', {
	provider: Storage.Providers.AmazonS3
	container: '',
	key: '',
	keyId: ''
});

// Call as many times as you want
Storage.add('otherProvider', {...});

Storage.get('myProvider', function (err, client) {
	// do your job
});
```

Configuration object should always contain `provider` key with either `Storage.Providers` brought to you by default or a custom package from npm attached via e.g. `require()`. After that, include other, provider-specific keys.

## Usage

**Uploading**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.upload('/path/to/your/file', '/remote/path', function (err, result) {
        // do your job
    });
});

```
Result object we receive on successful callback looks like the following one:

```js
{
	container: 'container_name',
	path: 'path_to_file' // relative to container,
	filename: 'file_name',
	url: 'full_url_to_a_file'
}
```

**Removing**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.remove('/remote/path', function (err) {
		// do your job
	});
});
```

Error object is empty when operation was successful.

**Downloading**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.download('/remote/path', '/local/path', function (err) {
		// do your job
	});
});
```

Error object is empty when operation was successful.

**See detailed provider-specific docs for better explanation of above methods and their meaning.**

## Motivation

If you ever wanted to implement storage integration right in your application - we got you covered. You've probably encountered problems with different libraries, especially if you wanted to integrate two or three providers, just to give your users a better choice. That's why `Storage.js` was created. Wrapping multiple libraries and creating simple abstraction layer for them allows you to easily add about 5 providers at once!

## API Reference

Will be published soon under github pages. To generate it on your own, simply run `gulp doc` task.

## Tests

With our 100% code coverage, we believe they are important. To run them by yourself, simply type `npm test`. For code coverage, use `gulp coverage`. Remember to delete html files generated by that command by executing `gulp remove-coverage`.
<commit_msg>Added Hooks draft<commit_after>Storage.js [![Travis-Ci](https://travis-ci.org/keystonejs/storage.js.svg)](https://travis-ci.org/keystonejs/storage.js)&nbsp;[![Code Climate](https://codeclimate.com/github/keystonejs/storage.js/badges/gpa.svg)](https://codeclimate.com/github/keystonejs/storage.js)&nbsp;[![Test Coverage](https://codeclimate.com/github/keystonejs/storage.js/badges/coverage.svg?v=2)](https://codeclimate.com/github/keystonejs/storage.js)&nbsp;[![Dependency Status](https://gemnasium.com/keystonejs/storage.js.svg)](https://gemnasium.com/keystonejs/storage.js)
==========

Storage.js is a NodeJS library that standarizes common available via `npm` libraries like `pkgcloud` and abstracts away differences (especially within callbacks). Just write a simple implementation and leave configuration up to your users.

* Available storage providers:
	* Rackspace
	* Amazon
	* Azure
	* Openshift
	* HP
	* Local disk
	* MongoDB

* To be included soon:
	* Dropbox, Google Drive
	* You tell me :)

* After initial release
	* (S)FTP - due to lack of nice, up-to-date modules, this is for now on hold.

> More providers will be added upon community requests (feel free to create an issue).

## Installation

*Note: Work in progress*. Although it's still work in progress, feel free to fork or do the custom install via `npm`. Further details will be published soon.

## Configuration

After requiring for the first time, invoke either `init` or `add` method by passing configuration object.

```js
var Storage = require('storage');

// #1 option
Storage.init({
	myProvider: {
		provider: Storage.Providers.AmazonS3
		container: '',
		key: '',
		keyId: ''
	},
	// other providers you need in your app
	{...}
});

// #2 option
Storage.add('myProvider', {
	provider: Storage.Providers.AmazonS3
	container: '',
	key: '',
	keyId: ''
});

// Call as many times as you want
Storage.add('otherProvider', {...});

Storage.get('myProvider', function (err, client) {
	// do your job
});
```

Configuration object should always contain `provider` key with either `Storage.Providers` brought to you by default or a custom package from npm attached via e.g. `require()`. After that, include other, provider-specific keys.

## Usage

**Uploading**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.upload('/path/to/your/file', '/remote/path', function (err, result) {
        // do your job
    });
});

```
Result object we receive on successful callback looks like the following one:

```js
{
	container: 'container_name',
	path: 'path_to_file' // relative to container,
	filename: 'file_name',
	url: 'full_url_to_a_file'
}
```

**Removing**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.remove('/remote/path', function (err) {
		// do your job
	});
});
```

Error object is empty when operation was successful.

**Downloading**

```js
Storage.get('myProvider', function (err, client) {
	if (err) return;
	client.download('/remote/path', '/local/path', function (err) {
		// do your job
	});
});
```

Error object is empty when operation was successful.

**See detailed provider-specific docs for better explanation of above methods and their meaning.**

## Hooks

You can hook either before or after one of the following methods: `upload`, `download`, `remove`.

### Usage

Your method passed to a hook will be called with following arguments:
* `next` method to call on end. If error is passed, other hooks and entire method will be skipped,
* list of the method arguments.

For further information on how hooks work - visit [`hook.js`](https://github.com/bnoguchi/hooks-js) repository.

### Global hooks

Useful if you need a global hook for every provider.

```js
Storage.pre('upload', function (next, localSrc) {
	next();
});
```

### Local hooks

To define a local hook, you can either do it globally or after receiving instance of your client.

```js
Storage.pre('yourProviderName', 'upload', function (next) {
	next();
});
Storage.get('yourProviderName', function (err, client) {
	client.pre('upload', function (next) {
		next();
	});
	// do your upload
});

## Motivation

If you ever wanted to implement storage integration right in your application - we got you covered. You've probably encountered problems with different libraries, especially if you wanted to integrate two or three providers, just to give your users a better choice. That's why `Storage.js` was created. Wrapping multiple libraries and creating simple abstraction layer for them allows you to easily add about 5 providers at once!

## API Reference

Will be published soon under github pages. To generate it on your own, simply run `gulp doc` task.

## Tests

With our 100% code coverage, we believe they are important. To run them by yourself, simply type `npm test`. For code coverage, use `gulp coverage`. Remember to delete html files generated by that command by executing `gulp remove-coverage`.

{'fraction_non_alphanumeric': 0.12703365277468243, 'fraction_numerical': 0.0020057945174949856, 'mean_word_length': 4.416415208207604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 17, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1101080', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2592, 'n_words': 993}