8.0.1 • Published 2 months ago

@cloudcmd/fileop v8.0.1

Weekly downloads
342
License
MIT
Repository
github
Last release
2 months ago

Fileop License NPM version Build Status

File operations emitter middleware.

Install

npm i @cloudcmd/fileop

Client

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

fileop(options, ): Promise

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';
const operator = await fileop({
    prefix,
});

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, {
    // default
    prefix: '/fileop', // string or a function
    root: '/',
    auth: (accept, reject) => (username, password) => {
        if (username === 'root' && password === 'toor')
            accept();
        
        reject();
    },
});

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

License

MIT

8.0.1

2 months ago

8.0.0

2 months ago

7.1.0

8 months ago

7.0.0

1 year ago

6.0.0

1 year ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.6

5 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago