UNPKG

3.5 kBMarkdownView Raw
1# MEGAJS
2
3Unofficial JavaScript SDK for MEGA
4
5* This is based on [tonistiigi's mega library](https://github.com/tonistiigi/mega).
6* This is all unofficial, based on [developer guide](https://mega.nz/#developers) and site source.
7* Make sure you agree with MEGA's [Terms of Service](https://mega.nz/#terms) before using it.
8* Maybe an official SDK will probably be released in the future here: https://github.com/meganz/
9
10## Installation
11
12```shell
13npm install megajs
14```
15
16```javascript
17const mega = require('megajs') // or
18import mega from 'megajs' // or
19// load it using <script> and use exported `mega` global directly
20```
21
22**API documentation and examples check Wiki: https://github.com/qgustavor/mega/wiki**
23
24The bundled files are available via [npm](https://www.npmjs.com/package/megajs) and [UNPKG](https://unpkg.com/megajs/dist/).
25
26**For CLI usage check MEGAJS CLI**: https://github.com/qgustavor/megajs-cli
27
28## Implementation notes:
29
30Only part of the file related API is implemented. For now implementing contact and chat functions seems out of scope.
31
32Cryptography is mostly ported from browser code. In Node some parts are optimized: AES operations are done using native crypto. Sadly WebCrypto don't support streaming so in browser the old pure JavaScript implementation is used. The RSA operations aren't optimized as currently there isn't any need to improve that.
33
34This module works in the browser: the "main.browser-umd.js" is a build using the UMD format where Node specific modules, like crypto and request modules, were replaced with browser equivalents. If you want to use tree shaking then use the "main.browser-es.js" bundle. This module wasn't tested in other environments.
35
36## Warning: unstable!
37
38As this library is a work in progress sometimes things may break, most because the code don't have a good coverage.
39
40Breaking changes are avoided when possible, but then **don't use any function that's not documented** as those can be removed or replaced any time.
41
42## Fork objectives:
43
44This package started as a fork, with the following objectives:
45
46* Make the original package work in browsers again: even following [the instructions from the original library](https://github.com/tonistiigi/mega#browser-support) it stopped working because some dependencies used `__proto__`, which is non-standard and isn't supported in many browsers. Also the updated versions of those libraries broke backyards compatibility;
47* Reduce dependencies and replace big dependencies with smaller ones, like crypto libraries, which usually are huge;
48* Rewrite code using the new JavaScript syntax, allowing to use [Rollup](http://rollupjs.org/), which can generate smaller bundles;
49* Make tests work again after the changes above;
50* Continue the original library development implementing new features and improving performance.
51
52Request package was replaced with a shim based in [browser-request](https://www.npmjs.com/package/browser-request) and [xhr-stream](https://www.npmjs.com/package/xhr-stream), which additional changes in order to make it work inside Service Workers. Crypto was replaced with [secure-random](https://www.npmjs.com/package/secure-random).
53
54As there were many changes there isn't any plan to merge those changes into the original library, unless the original author accept those massive changes. That's why I put "js" in the name, which is silly because both libraries use JavaScript. At least it's better than other ideas I had, like "mega2", "mega-es" and "modern-mega".