espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.75k stars 739 forks source link

add pipe method to StorageFile #2350

Closed mariusGundersen closed 1 year ago

mariusGundersen commented 1 year ago

This adds the pipe method to storage files, so they can be piped to for example an http request or response.

I have tested and this seems to work:

const logFile = Storage.open("log", "r");

// without this change
E.pipe(logFile, req);

// with this change:
logFile.pipe(req)
gfwilliams commented 1 year ago

This looks great, thanks! I guess just having the read(num) method is good enough to make it work.

I'm wondering whether it makes sense to allow E.pipe to take a String as a source? It would then allow piping of large (non-StorageFile) files in storage to a socket - which I guess you can't easily do