How to use request-progress - 7 common examples

To help you get started, we’ve selected a few request-progress examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EragonJ / Kaku / src / modules / DownloadManager.js View on Github external
download(src, path) {
    const req = RequestProgress(Request.get(src), {
      delay: 1000 // start to emit after 1000ms delay
    });

    req.on('progress', (state) => {
      this.emit('download-progress', Math.floor(state.percentage * 100));
    })
    .on('error', (error) => {
      console.log('error when requesting file');
      console.log(error);
      this.emit('download-error');
    })
    .pipe(Fs.createWriteStream(path))
    .on('error', (error) => {
      console.log('error when saving file to path' + path);
      console.log(error);
      this.emit('download-error');
github trazyn / ieaseMusic / submodules / downloader / index.js View on Github external
return new Promise((resolve, reject) => {
        var r = request({
            url,
            headers: {
                'Origin': 'http://music.163.com',
                'Referer': 'http://music.163.com/',
            },
            timeout: 10000,
        });

        rp(r)
            .on('error',
                err => {
                    delete cancels[canceler];

                    // https://github.com/request/request/blob/a92e138d897d78ce19dd70bd1ad271c7f9c6a23d/request.js#L1167
                    if (r._aborted) {
                        reject(new Error('_aborted'));
                    } else {
                        reject(err);
                    }
                }
            )
            .on('progress',
                state => {
                    callback.size = state.size || {};
                    callback(state);
github nylas-mail-lives / nylas-mail / src / flux / stores / file-download-store.es6 View on Github external
started: (req) => {
              this.attempts += 1;
              this.request = req;
              return progress(this.request, {throtte: 250})
              .on('progress', (prog) => {
                this.percent = prog.percent;
                this.progressCallback();
              })

              // This is a /socket/ error event, not an HTTP error event. It fires
              // when the conn is dropped, user if offline, but not on HTTP status codes.
              // It is sometimes called in place of "end", not before or after.
              .on('error', onFailed)

              .on('end', () => {
                if (this.state === State.Failed) { return; }

                const {response} = this.request
                const statusCode = response ? response.statusCode : null;
                if ([200, 202, 204].includes(statusCode)) {
github SomeoneWeird / aergia / app / containers / entrypoints / soundhax / setup / index.js View on Github external
downloadFile (filename, url, done) {
    this.setState({
      ...this.state,
      progress: 0
    })
    console.log('downloading to', path.resolve(config.drive.mountPoint, filename))
    requestProgress(request(url))
      .on('progress', (state) => {
        this.setState({
          ...this.state,
          progress: (state.percent * 100).toFixed(0)
        })
      })
      .on('end', (err) => {
        if (err) {
          return done(err)
        }
        this.setState({
          ...this.state,
          progress: 100
        })
        return done()
      })
github alibaba / ice / tools / iceworks / renderer / src / stores / custom-blocks.js View on Github external
loadMaterialData() {
    if (this.dataLoading) {
      this.progressVisible = true;
    }
    if (!this.materialData) {
      this.dataLoading = true;
      this.progressTitle = '下载物料数据';
      requestProgress(
        request(
          'http://ice.alicdn.com/iceland-assets/material-engine-production.json',
          (error, response, body) => {
            if (!error) {
              this.materialData = body;
              this.getEngine('react');
              this.loadIconData();
            } else if (this.requestCount < 3) {
              this.requestCount++;
              this.loadMaterialData();
            } else {
              this.requestCount = 0;
              this.errorVisible = true;
              this.dataLoading = false;
              this.progressVisible = false;
            }
github zeit / pkg-fetch / lib / github.js View on Github external
return new Promise((resolve, reject) => {
      const headers = { Accept: 'application/octet-stream' };
      const ws = fs.createWriteStream(file);
      let result;
      const req = progress(this.request.get(url, {
        headers
      }, (error, response) => {
        if (error) {
          log.disableProgress();
          return reject(wasReported(error.message));
        }
        if (response.statusCode !== 200) {
          log.disableProgress();
          const message = `${response.statusCode} ${response.body}`;
          return reject(wasReported(message, url));
        }
        result = response;
      }));
      req.on('progress', (state) => {
        let p;
        if (state.size && state.size.transferred && state.size.total) {
github alibaba / ice / tools / iceworks / renderer / src / stores / custom-blocks.js View on Github external
loadIconData() {
    if (!this.iconData) {
      this.progressTitle = '下载 Iconfont 数据';
      requestProgress(
        request('http://ice.alicdn.com/iceland-assets/iconData.json',
          (error, response, body) => {
            if (!error) {
              this.materialProgress = 100;
              this.iconData = body;
              this.dataLoading = false;
              this.progressVisible = false;
              this.dataTest();
            } else if (this.requestCount < 3) {
              this.requestCount++;
              this.loadIconData();
            } else {
              this.requestCount = 0;
              this.errorVisible = true;
              this.dataLoading = false;
              this.progressVisible = false;

request-progress

Tracks the download progress of a request made with mikeal/request, giving insight of various metrics including progress percent, download speed and time remaining

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular request-progress functions