-
• #2
Sat 2019.01.12
Performing a Google search, remember Google is your friend,
Google: E.openFile site:espruino.com
a lengthy discussion and solution was previously proposed
-
• #3
Ha! Thank you. I used the forum search for "openfile" without results ;(
Here is one solution to help other users.
It fixes the heap leak, but still eventually fails to open the file.
var f = E.openFile(a.pathname, "r"); if (f !== undefined) { // File open succeeded - send it! res.writeHead(200, {'Content-Type': 'text/plain'}); f.pipe(res, {chunkSize: 512, complete: f.close}); } else { // couldn't open file res.writeHead(404, {'Content-Type': 'text/plain'}); res.end("404: Page "+a.pathname+" not found"); }
Hello everybody,
I am experimenting a bit with the http server (espruino versions from 1.99) and this snippet works most of the time.
First time the page is opened it shows the files in the system as hyperlinks. Downloading a file many times breaks the code.
I´ve found that calling E.openFile many times in the left webide pane makes it fail too. No examples show a close method after openFile, so I believe that it is not needed.
Am I doing it wrong?