Skip to content
Unofficial JavaScript SDK for MEGA
JavaScript
Branch: master
Clone or download
qgustavor Update Node versions in Travis
Tests weren't passing in Node 6... but, look, it's not supported anymore!
Latest commit 0b359f3 Jun 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
browser Fix some bugs Dec 7, 2018
lib Fix some bugs Dec 7, 2018
test Update mega-mock and add new tests Dec 9, 2018
.babelrc Update build process and dependencies May 7, 2018
.gitignore Remove package-lock.json May 8, 2018
.travis.yml Update Node versions in Travis Jun 8, 2019
build.js Fix some bugs Dec 7, 2018
package.json Update mega-mock and add new tests Dec 9, 2018
readme.md Update the readme Apr 13, 2019

readme.md

MEGAJS

Unofficial JavaScript SDK for MEGA

Installation

npm install megajs
const mega = require('megajs') // or
import mega from 'megajs'

You can also load it in a browser using <script src="https://unpkg.com/megajs/dist/main.node-cjs.js"></script>, which exports the library in the mega global variable. You can also use import * as mega from 'https://unpkg.com/megajs/dist/main.browser-es.js'.

For more details, API documentation and examples check wiki: https://github.com/qgustavor/mega/wiki

The bundled files are available via npm and UNPKG.

For CLI usage check MEGAJS CLI: https://github.com/qgustavor/megajs-cli

Implementation notes

Only part of the file related API is implemented. For now implementing contact and chat functions seems out of scope.

Cryptography 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.

This 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.

Fork objectives

This package started as a fork, with the following objectives:

  • Make the original package work in browsers again: even following the instructions from the original library 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;
  • Reduce dependencies and replace big dependencies with smaller ones, like crypto libraries, which usually are huge;
  • Rewrite code using the new JavaScript syntax, allowing to use Rollup, which can generate smaller bundles;
  • Make tests work again after the changes above;
  • Continue the original library development implementing new features and improving performance.

Request package was replaced with a shim based in browser-request and xhr-stream, which additional changes in order to make it work inside Service Workers. Crypto was replaced with secure-random.

As 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".

Contributing

When contributing fork the project, clone it, run npm install, change the library as you want, run tests using npm run test and build the bundled versions using npm run build. Before creating a pull request, please, run tests.

You can’t perform that action at this time.