Skip to content
file operations emitter middleware
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
client
server
test
.babelrc
.eslintrc.json
.eslintrc.server
.gitignore
.npmignore
.travis.yml
ChangeLog
LICENSE
README.md
madrun.js
package.json
webpack.config.js

README.md

Fileop License NPM version Dependency Status Build Status

File operations emitter middleware.

Install

npm i @cloudcmd/fileop

Client

Could be loaded from url /fileop/fileop.js.

fileop([options, ] callback)

Initialize operator.

  • options:
    • prefix - prefix of fileop (/fileop by default)
    • socketPrefix - prefix of socket.io (`` by default)

Returns operator in callback.

operator

It is EventEmitter from the inide produce next types of events:

  • error
  • progress
  • file
  • end

Supports next types of operations:

  • operator.copy(from, to, names)
  • operator.move(from, to, names)
  • opreator.remove(from, names)
  • opreator.extract(from, to)
  • operator.zip(from, to)
  • operator.tar(from, to)
const prefix = '/fileop';

fileop((error, operator) => {
    const from = '/';
    const to = '/tmp';
    const names = [
        'bin'
    ];
    const progress = (value) => {
        console.log('progress:', value);
    };
    
    const end = (op) => () => {
        console.log('end');
        op.removeListener('progress', progress);
        op.removeListener('end', end);
    };
    
    const error = (op) => (data) => {
        const msg = data + '\n Continue?';
        const is = confirm(msg);
        
        if (is)
            return op.continue();
        
        op.abort();
    };
    
    operator.copy(from, to, names).then((op) => {
        op.on('progress', progress);
        op.on('end', end(op));
        op.on('error', error(op));
    });
});

Server

const fileop = require('fileop');
const http = require('http');
const express = require('express');
const io = require('socket.io');
const app = express();
const port = 1337;
const server = http.createServer(app);
const socket = io.listen(server);

server.listen(port);

app.use(fileop({
    prefix: '/fileop', /* default */
}));

fileop.listen(socket, {
    prefix: '/fileop',   /* default              */
    root: '/',           /* string or a function */
    auth: (accept, reject) => (username, password) => {
        if (username === 'root' && password === 'toor')
            accept();
        
        reject();
    },
});

License

MIT

Related

  • Spero - file copy emitter middleware based on socket.io and copymitter
  • Remedy - emitting middleware for file removing
  • Ishtar - pack and extract .tar.gz archives middleware
  • Omnes - extract zip, gz, tar, tar.gz, tgz archives middleware
  • Salam - pack and extract zip archives middleware
You can’t perform that action at this time.