GithubHelp home page GithubHelp logo

Comments (6)

sayem314 avatar sayem314 commented on June 1, 2024

You are suppose to respect issue template when creating issue, the template exists for a reason. BTW stream example is documented here > https://github.com/sayem314/hooman#pipe-stream

from hooman.

sayem314 avatar sayem314 commented on June 1, 2024

Related issue you can read on to grasp more details: #3

from hooman.

Clemv95 avatar Clemv95 commented on June 1, 2024

Yeah sorry about that it's m'y first issue on github.
I dont understand what is the await lign for pipe can you help ?

from hooman.

sayem314 avatar sayem314 commented on June 1, 2024

@Clemv95 no problem then.

you can use it like this:

const fs = require('fs');
const request = require('request');
const emojis = require('./emojis.json');
const hooman = require('hooman');

const download = async function(uri, filename, callback) {
  let file = fs.createWriteStream(filename);
  let r = hooman.stream(uri).pipe(file);
  r.on('error', function(err) {
    console.log(err);
  });
  r.on('finish', function() {
    file.close(callback);
  });
};

hooman
  .get(siteUrl)
  .then((res) => {
    for (let i = 0; i < emojis.length; i++) {
      nom = emojis[i].image.slice(emojis[i].image.indexOf('emoji/') + 6, emojis[i].image.length);
      download(emojis[i].image, './emojis/' + nom, function(err) {
        console.log(err);
      });
    }
  })
  .catch((err) => {
    console.log(err.message);
  });

siteUrl is the main base url of images where you will download images from. first you make dummy request to initialize cookie.

from hooman.

sayem314 avatar sayem314 commented on June 1, 2024

You can also use this function for image/small binary files.

const download = async function(uri, filename, callback) {
  try {
    const { body } = await hooman.get(uri, {
      responseType: 'buffer',
    });
    // Write image to file
    fs.writeFileSync('image.jpg', body);
    console.log('Done');
  } catch (err) {
    callback(err);
  }
};

from hooman.

sayem314 avatar sayem314 commented on June 1, 2024

Quick full example based your code:

const fs = require('fs');
const request = require('request');
const emojis = require('./emojis.json');
const hooman = require('hooman');

const download = async function(uri, filename, callback) {
  try {
    const { body } = await hooman.get(uri, {
      responseType: 'buffer',
    });
    // Write image to file
    fs.writeFileSync(filename, body);
    callback();
  } catch (err) {
    callback(err);
  }
};

for (let i = 0; i < emojis.length; i++) {
  nom = emojis[i].image.slice(emojis[i].image.indexOf('emoji/') + 6, emojis[i].image.length);
  download(emojis[i].image, './emojis/' + nom, function(err) {
    console.log(err);
  });
}

from hooman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.