File operations emitter middleware.
npm i @cloudcmd/fileop
Could be loaded from url /fileop/fileop.js.
Initialize operator.
options:prefix- prefix offileop(/fileopby default)socketPrefix- prefix ofsocket.io(`/fileop' by default)
Returns operator in callback.
It is EventEmitter from the inide produce next types of events:
errorprogressfileend
Supports next types of operations:
operator.copy(from, to, names)operator.move(from, to, names)operator.remove(from, names)operator.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(); }; const op = await operator.copy(from, to, names); op.on('progress', progress); op.on('end', end(op)); op.on('error', error(op));
import http from 'node:http'; import {fileop} from 'fileop'; import express from 'express'; import {Server} from 'socket.io'; const app = express(); const port = 1337; const server = http.createServer(app); const socket = new Server(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(); }, });
- Spero - file copy emitter middleware based on
socket.ioandcopymitter - 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
MIT