danielgtaylor / aglio

An API Blueprint renderer with theme support that outputs static HTML
4.75k stars 480 forks source link

allow to read longer files from stdin #364

Open anentropic opened 5 years ago

anentropic commented 5 years ago

Trying to read large blueprints from stdin fails, giving a syntax error which suggests the content was truncated. Reading the same file in via -i <filename> method works fine, so there is no issue with the file itself.

The length of the content I got was always 65536 bytes, suggesting some issue around buffering.

After experimenting it turns out that what actually happens is the process.stdin.on 'readable' event handler gets called multiple times for large files - for each block of data from the buffer.

So the fix is to build up the blueprint content over a series of readable events and wait until the end event is triggered before trying to process it.