Skip to content

stream support #16

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

Open
sarkistlt opened this issue May 8, 2018 · 4 comments
Open

stream support #16

sarkistlt opened this issue May 8, 2018 · 4 comments

Comments

@sarkistlt
Copy link

any plans on supporting stream? buffer is cool, but what if I just don't want to load the whole file, and just want to stream it from my API to swift or s3 object storage. Would be supper useful to be able pipe to stream

@michielverkoijen
Copy link

There are no update plans for the clients right now but I'm happy to note your request and share the idea with the development team.

@HydraOrc
Copy link

HydraOrc commented Dec 5, 2018

I've just tested it with node.js (6.15.1), and you should be able to use the default streams functionality:

import request from 'request';

const r = request.post('https://api:your_key@api.tinify.com/shrink', (err, resp, body) => {
    const obj = JSON.parse(body);

    request.get(obj.output.url); // <== your compressed file url, also pipeable
});

stream.pipe(r);

@sarkistlt
Copy link
Author

@HydraOrc hm, didn't thought about directly using API url, looks good, will try, thanks!
But I think you need pipe request.get stream, instead of r, if you want to stream compressed file to write stream distention.

@HydraOrc
Copy link

HydraOrc commented Dec 6, 2018

@sarkistlt I mean that at first you should pipe your stream to the post request (r in the case above) to send your data to the tinify api server.
And after that in a callback you could also pipe the request.get(obj.output.url) to write the compressed result to any destination you want to.
In my case it is writing a file to a GridFS storage and it works perfectly, but it could be something else.

For example:
request.get(obj.output.url).pipe(fs.createWriteStream('filename.txt'));

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

No branches or pull requests

4 participants