siwi-file
v1.0.3
Published
file download for nodejs
Downloads
14
Maintainers
Readme
siwi-file
file download for nodejs
install
use npm
npm install siwi-file
use yarn
yarn add siwi-file
Example
code example download nodejs pkg
(async () => {
const path = require('path')
const { file } = require('./index')
const url = 'https://nodejs.org/dist/v11.11.0/node-v11.11.0.pkg'
const savepath = path.resolve('./storage', 'node-v11.11.0.pkg')
try {
await file(url, savepath)
console.log('下载完成');
} catch (error) {
console.trace(error)
}
})()
run node test.js
node test.js
Test
npm test
const expect = require('chai').expect
describe('siwi-file.js', () => {
it('file', async () => {
const { file } = require('../lib')
const fs = require('fs')
const path = require('path')
const url = 'https://mac-torrent-download.net/wp-content/uploads/tr-files/2019-q1/50c621b678278d22e81056cbb9827694.torrent'
const basename = path.basename(url)
const savepath = path.resolve('./storage/torrents', `${basename}`)
await file(url, savepath)
const res = fs.existsSync(savepath)
expect(res).to.be.equal(true)
});
});