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

What should the syntax be like? #3

Closed
jimmywarting opened this issue Jun 1, 2016 · 4 comments
Closed

What should the syntax be like? #3

jimmywarting opened this issue Jun 1, 2016 · 4 comments

Comments

@jimmywarting
Copy link
Owner

I would want the syntax to be dead simple like FileSaver.js where you just type

saveAs(blob, "filename")

// So something along with this?
saveStream(stream, "filename")

// The stream api defines something like .pipeTo()
// so the correct syntax would be something where you create two streams
// This is very much like how NodeJS dose it so there is a familiar language here
stream.pipeTo( createWriteStream("filename") )

One problem I see with .pipeTo() is that it's not widely adopted yet.
Maybe we want save more than just streams that are not streams but could as well act like a stream? What could that be? what can we save?

  • Webpacks or browserify streams
  • Fetch's .getReader()
  • Chromes sandboxed filesystem?
  • Blobs and files
  • FileReader?
  • userMedia streams
  • DataChannel
  • postMessage
  • sockets
  • streams (camera, screen, audio & ReadableStream)

Surely we can't adopt everything into the same function that dose all magic depending on what type it's
but we can help turn each of them into a stream that can then be used by each other

@jimmywarting
Copy link
Owner Author

Funny, just thought: "we already have FileReader, why not FileWriter?"

var writer = new FileWriter('filename')
writer.readAsBlob(blob)
writer.readAsSocket(new WebSocket)
writer.readAsStream(audioStream)

Maybe cuz it's a bad idéa and we have to support all of them.
perhaps just better to enforce a stream and build other function around that

How about:

var writer = new FileWriter(stream, 'filename')
// writer.methods? writer.close()

still think you should close it using the streams close method instead...
but then again, you maybe want to keep recording the camera without closing the the stream how do you then stop the writer?

let writeStream = createWriteStream("filename")
stream.pipeTo( writeStream )

writeStream.close()
// stream is still alive

@jimmywarting
Copy link
Owner Author

jimmywarting commented Jun 3, 2016

One thing that i have experience when using this for a little while now with this syntax

saveStream(stream, "filename")

Is that: if you want to close the stream-saver you would need to close the stream you are trying to save...
I believe it's undesirable?
For example: I want to show a <video> tag what it looks like. But don't want to start recording until user press the record button. When I want to stop writing to the filesystem then I don't want to stop the <video> tag. I still want to show a preview of what it looks like.

I'm leaning more towards creating a createWriteStream('filename')
that way when you close the writer it will stop saving to the disk, and if you close the mediaStream it will signal to the writer (if you have piped it) that it should also close

@jimmywarting jimmywarting added this to the 1.0.0 milestone Jun 3, 2016
@jimmywarting
Copy link
Owner Author

@eligrey and everyone else do you have some spare time to look at the difference?

I have experience with both

saveStream(stream, "filename")

And also this: (checkout the Writable branch)

var myFile = fs.createWriteStream("filename")
myFile.write("abc")
// you could also do this:
let stream = fs.createBlobReader(blob)
stream.pipeTo(myFile)

What do you think is best?

@jimmywarting
Copy link
Owner Author

I know now what i want...

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

1 participant