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

Uncaught TypeError: writer.on is not a function #2

Open
gilbitron opened this issue Feb 1, 2017 · 1 comment
Open

Uncaught TypeError: writer.on is not a function #2

gilbitron opened this issue Feb 1, 2017 · 1 comment

Comments

@gilbitron
Copy link

Trying to use this but when the cache is downloading I get the following error:

node_modules/aws-sdk/lib/request.js:1006: Uncaught TypeError: writer.on is not a function

Any ideas?

@jpgilchrist
Copy link

Well this is a year later... I'm not sure if the author has kept up with this at all... but it's because the code for the getCache method expects the response from client.getObject to be a stream an dit's not.

The existing code:

    client.getObject({
      Bucket: options.bucket,
      Key: options.cacheDest
    }, function(err, res) {
      if (err && err.statusCode !== 404) return callback(err)
      if (err && err.statusCode === 404) return callback(null)

      es.pipeline(
          res
        , es.split()
        , es.parse()
        , LevelWriteStream(db)()
      ).once('close', callback)
       .once('error', callback)
    })

and what it should be...

    client.getObject({
        Bucket: options.bucket,
        Key: options.cacheDest
    }).createReadStream()
        .once('error', (err) => {
              if (err && err.statusCode !== 404) return callback(err)
              if (err && err.statusCode === 404) return callback(null)
        })
        .pipe(es.split())
        .pipe(es.parse())
        .pipe(LevelWriteStream(db)())
        .once('close', callback)
        .once('error', callback);

Unfortunately I had to hack it a bit with adding

      events.EventEmitter.defaultMaxListeners = 300; // no idea what this number actually should be... I just picked a high number
      client.getObject(...)...

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

Successfully merging a pull request may close this issue.

2 participants