npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@winkgroup/mega

v2.2.2

Published

Library for mega.nz

Downloads

125

Readme

mega

Library for mega.nz. It suppose you have mega-cmd installed and available from any directory.

It provides two main classes:

  • MegaCmd: a wrapper for mega terminal commands
  • StorageMega: an abstraction to manage mega repository as a storage

Install

npm install @winkgroup/mega

MegaCmd

This is basically a wrapper for mega-* commands. Mapped commands are:

  • df
  • get
  • login
  • logout
  • ls
  • proxy
  • put
  • rm
  • whoAmI for further explanation you can run mega-help

Since you can be logged only with one account a time, a locking system is provided to avoid to have multiple instances of MegaCmd running at the same time. Here an example to get a megaCmd instance:

    let megaCmd = await MegaCmd.get('myLockingWord') // returns instance of MegaCmd
    let megaCmd2 = await MegaCmd.get('someOtherWord') // returns null
    MegaCmd.unlock('myLockingWord')
    megaCmd2 = await MegaCmd.get('someOtherWord')// now returns instance of MegaCmd

    const booleanResult = await megaCmd2.login('[email protected]', 'myPassword')
    if (booleanResult) {
        const result = megaCmd2.df()
        console.log(result) // free bytes, etc...
    }
    megaCmd2.unlock('someOtherWord')

You can also decide to wait until megaCmd is available again and eventually set a timeout (default 1 hour). In this example it will return an instance of megaCmd as soon as megaCmd is available or will wait 10 minutes for it:

    const megaCmd = await MegaCmd.getOrWait('anyLockingWord', 600)

you can avoid the timeout setting the second param to 0

You can check by yourself if megaCmd is idle using MegaCmd.isIdle(): it will check if you are online and no other megaCmd instance locked the resource.

You can also subscribe the idle event that will be fired when you will be online and no other megaCmd have locked the resource. This method uses EventQueue library, this means you don't need to remove the listener when is fired and any listener is fired in sequence so the is unlikely that when the callback is fired you will need to wait any longer. Here an example:

    const handle = MegaCmd.onIdle.add(() => {
        console.log('put here some code has to run when MegaCmd is in idle state')
        ...
    })

    ...
    // later on if you need to delete the listener of any reason:
    MegaCmd.onIdle.remove(handle)

get and put commands

These two commands can manage also the progress during the transfer providing an EventEmitter instance, here and example:


    const megaCmd = await MegaCmd.get('myLockingWord')
    const onTransfer = new EventEmitter()
    onTransfer.on('progress', (data) => {
        console.log(`${ data.bytes } of ${ data.totalBytes } (${ data.percentage}%) transferred`)
    })
    await megaCmd.login('[email protected]', 'myPassword')
    await megaCmd.get('myRemoteFilePath', 'localPath', { onTransfer: onTransfer }) // this will output the progress during the transfer session
    ...

Playground as Interactive Integration Test

under playground folder some extra code is provided to make some interctive integration tests. This is a command line interface to manage the storage of a specific Mega account. Here the steps to run this test:

  1. copy playground/config.template.json to playground/config.json
  2. edit playground/config.json setting the credetials of a real mega account
  3. run npm run playground or yarn playground

Maintainers