5.0.3 • Published 1 month ago

@cloudcmd/dropbox v5.0.3

Weekly downloads
273
License
MIT
Repository
github
Last release
1 month ago

Dropbox License NPM version Build Status Coverage Status

Dropbox files and folders CRUD.

Install

npm i @cloudcmd/dropbox --save

API

All functions requires token as first parameter

readDir(token, path, options)

  • token - string
  • path - string
  • options - object can contain:
    • sort - sort by: name, size, date
    • order - "asc" or "desc" for ascending and descending order (default: "asc")
    • type - when "raw" returns not formatted result

Example

const sort = 'size';
const order = 'desc';
const token = 'token';
const path = '/';
const type = 'raw';

const {readDir} = require('@cloudcmd/dropbox');

const files = await readDir(token, path, {
    type,
    sort,
    order,
});

console.log(files);
// outputs
({
    path: '/',
    files: [{
        name: 'dropbox.js',
        size: 4735,
        date: 1_377_248_899_000,
        owner: 0,
        mode: 0,
    }, {
        name: 'readify.js',
        size: 3735,
        date: 1_377_248_899_000,
        owner: 0,
        mode: 0,
    }],
});

readFile(token, path)

  • token - token
  • path - path to file

Example

const {readFile} = require('@cloudcmd/dropbox');

const readStream = await readFile(token, '/dropbox.html');
readStream.pipe(process.stdout);

writeFile(token, path, contents)

  • token - token
  • path - path to file
  • contents - contents of a file

Example

const {writeFile} = require('@cloudcmd/dropbox');

await writeFile(token, '/hello.txt', 'hello');

createWriteStream(token, path)

  • token - token
  • path - path to file

Example

const {createReadStream} = require('fs');
const {createWriteStream} = require('@cloudcmd/dropbox');

const token = 'token';
const path = '/file';

const dropboxStream = createWriteStream(token, path);
const localStream = createReadStream(path);

localStream
    .pipe(dropboxStream)
    .on('error', console
        .error)
    .on('finish', console.log);

createReadStream(token, path)

  • token - token
  • path - path to file

Example

const {createWriteStream} = require('fs');
const {createReadStream} = require('@cloudcmd/dropbox');

const token = 'token';
const path = '/file';

const dropboxStream = createReadStream(path);
const localStream = createWriteStream(token, path);

dropboxStream
    .pipe(localStream)
    .on('error', console
        .error)
    .on('finish', console.log);

remove(token, path)

remove file/directory.

  • token - token
  • path - path to file

Example

const {remove} = require('@cloudcmd/dropbox');

await remove(token, '/fileOrDir');

mkdir(token, path)

create directory.

  • token - token
  • path - string

Example

const {mkdir} = require('@cloudcmd/dropbox');

await mkdir(token, '/dirname');

copy(token, from, to)

Copy file/directory to new location

  • token - token
  • from - path from
  • to - path to

Example

const {copy} = require('@cloudcmd/dropbox');

await copy(token, '/file1', '/file2');

move(token, from, to)

Move file/directory to new location

  • token - token
  • from - path from
  • to - path to

Example

const {move} = require('@cloudcmd/dropbox');

await move(token, '/file1', '/file2');

Related

  • readify - read directory content with file attributes: size, date, owner, mode
  • flop - FoLder OPerations
  • dropboxify - read directory content from dropbox compatible way with readify

License

MIT

5.0.3

1 month ago

5.0.2

1 month ago

5.0.1

1 month ago

5.0.0

1 month ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago