oss-sdk
v1.0.8
Published
oss-sdk contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.
Maintainers
Readme
Quickstart
====================
API Introduction...
======================================
1. Install
npm install oss-sdk2. Import package
let url = 'D:\\demo';
const oss = require('oss-sdk');3. API path
url = oss.path(url,'test') // D:\\demo\\test4. API cut
await oss.cut(oldRUL, newRUL); //true or false (dir or file)5. API copy
await oss.copy(oldRUL, newRUL); //true or false (dir or file)6. API rename
await oss.rename(oldRUL, newRUL); //true or false (dir or file)7 API dir
const dir = oss.dir(url);await dir.ok() //true or false
await dir.ok('test') //true or falseawait dir.add() //true or false
await dir.add('00') //true or false
await dir.add('01','02') //true or falseawait dir.list(); //Get the list 'D:\\demo\\test'
await dir.list('00'); //Get the list 'D:\\demo\\test\\00'await dir.rename('00', '000'); //true or falseawait dir.clear() //true or false
await dir.clear('01','02') //true or falseawait dir.dele() //true or false
await dir.dele('01','02') //true or false8. API file
const file = oss.file(url);await file.add('01.txt','520') //New File 'D:\\demo\\test\\01.txt'
await file.add('02.txt','22222') //New File 'D:\\demo\\test\\02.txt'await file.ok('01.txt') //true or false 'D:\\demo\\test\\01.txt'
await file.size('01.txt') //null or number 'D:\\demo\\test\\01.txt'await file.get('01.txt') //null or content 'D:\\demo\\test\\01.txt'await file.push('01.txt','1314') //Add text content 5201314 await file.edit('01.txt','5200') //Modify text content 5200 await file.rename('01.txt','03.txt') //true or false await file.dele('01.txt') //Delete file
await file.dele('01.txt','03.txt') //Batch delete files9. API read
const kbps = 1024; //1024kb
const encoding = 'utf8'; //Default to null
const stream = oss.read(filePath); //No speed limit
const stream = oss.read(filePath, kbps); //Limit 1024kb per second
const stream = oss.read(filePath, kbps, encoding); //The output method is utf8
stream.start((data) => {
// Process every piece of data
console.log(data);
}).ok(() => {
console.log('read completed');
}).err((msg) => {
console.error('Read failed:', msg);
})
stream.ps(()=>{
console.log('Pause reading');
})
stream.go(()=>{
console.log('Continue reading');
})
stream.stop(()=>{
console.log('Stop reading');
})10. API log.input
const input = oss.log.input('D:\\demo\\test.txt');
//Use gzip to compress data
//If it doesn't exist, it will be created
input.start(()=>{
input.add('Hello World!!') //Write as append by default
input.add('write data!!!') //Write as append by default
input.end(()=>{
console.log('End writing');
});
}).err((msg)=>{
//console.log('Error message');
})10. API log.output
const output = oss.log.output('D:\\demo\\test.txt');
//Use gzip to decompress data
output.start((data)=>{
// 逐行读取
is++
// console.log(data);
}).err((msg)=>{
//Printing error
console.log(msg);
}).ps(()=>{
console.log('Pause reading');
}).ok(()=>{
console.log('read completed');
})
setTimeout(()=>{
output.go(()=>{
console.log('Continue reading');
})
},1000)
setTimeout(()=>{
output.stop(()=>{
console.log('stop reading');
})
},2000);
11. API tgz
const ignore ['node_modules'];
//compressed file
await oss.tgz.min('D:\\resources','D:\\resources\\backup.ant',ignore);
//extract files
await oss.tgz.max('D:\\resources\\backup.ant','D:\\resources\\new');