Reputation: 6338
I'm trying to use Google Cloud Functions to transcode a video from one bucket to another. I have this:
const remoteWriteStream = bucket.file(dstFile).createWriteStream()
and then I pipe ffmpeg output to it. Right now I'm returning from my GCF as soon as ffmpeg finishes, but sometimes the file doesn't exist yet. I understand that stream "emits a finish
event" when it's complete.
I see from the docs at https://cloud.google.com/nodejs/docs/reference/storage/2.3.x/File#createWriteStream that createWriteStream()
returns a WritableStream
but I can't find any docs on that object, so I don't know how to wait for the "finish" event.
Upvotes: 1
Views: 1114
Reputation: 317710
If you understand how a node Writable works, then you understand how a WritableStream works. I think the JavaScript API docs are a bit confusing here. Here's what the TypeScript definition of File.createWriteStream looks like:
createWriteStream(options?: CreateWriteStreamOptions): Writable;
So you can see it actually just returns a Writable, which is defined like this in node:
class Writable extends Stream implements NodeJS.WritableStream { ... }
Upvotes: 1