Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle streams in a hook #262

Closed
eddyystop opened this issue Oct 1, 2017 · 5 comments
Closed

How to handle streams in a hook #262

eddyystop opened this issue Oct 1, 2017 · 5 comments

Comments

@eddyystop
Copy link
Collaborator

get: [
  hook => {
    const gfs = hook.app.get('gfs');

    const data = await gfs.files.find({ filename: 'xxxx.jpg' }).toArray();

    let bar;
    if (data) {
      return new Promise((resolve, reject) => {
        var buffer = "";
        bar = await gfs.createReadStream({ filename: 'xxxx.jpg' })
        // on lit le stream
        bar.on('data', function (chunk) {
          buffer += chunk;
        })
        bar.once('error', error => reject(error));
        // a la fin de la lecture
        bar.on('end', function () {
          // console.log('result is ', buffer)
          hook.result.buffer = 'FooBar'
          // hook.result.buffer = buffer.toString('utf8')
          console.log(hook.result)

          resolve(hook);
        });
      })
    }
  }
],
@bertho-zero
Copy link
Contributor

@eddyystop est français ?

@eddyystop
Copy link
Collaborator Author

Its sample code to start work from.

@bertho-zero
Copy link
Contributor

Seeing the comments in the sample, I thought you were French.

@eddyystop
Copy link
Collaborator Author

Je vis au Québec.

@eddyystop
Copy link
Collaborator Author

Streams is no longer a current topic in Feathers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants