Create readable and writable streams for downloading and uploading files to Yandex.Disk.
Each method requires an OAuth token. You can receive one manually or use one of OAuth library, i.e. passport-yandex-token.
Creates readable stream for downloading file from Yandex.Disk.
import fs from 'fs';
import { download as downloadStream } from 'ya-disk-stream';
const API_TOKEN = '9182h178d871gd8g23kwjehkwehr9';
const fileToSave = fs.createWriteStream('./Mountains.jpg');
downloadStream(API_TOKEN, 'disk:/Горы.jpg', (download) =>
download.pipe(fileToSave)
);
Creates writable stream for uploading file to Yandex.Disk.
import fs from 'fs';
import path from 'path';
import { upload as uploadStream } from 'ya-disk-stream';
const API_TOKEN = '9182h178d871gd8g23kwjehkwehr9';
const fileToUpload = fs.createReadStream(path.join(__dirname, 'upload.js'));
uploadStream(
API_TOKEN,
'disk:/upload.js',
true,
(stream) => fileToUpload.pipe(stream),
(err) => process.stderr.write(err)
);
By default feature tests aren't being run on git push. You should run the manually. In order to do that you need to create .env
in the root of the project containing your API_TOKEN
:
API_TOKEN=19823jd92u8h3d78efya0s7fyhaiu23ghjhg
After you may use npm test
command to run all tests or npm test -- features/*.feature.js
to run only feature tests.