When we enter a URL that we can't immediately transform, we check whether or not it's an image by going to the URL, grabbing the first 8 bytes and checking the value of those bytes against a table of values that indicate an image and it's type (PNG/JPG etc.).
After we grab the first few bytes of the request, we close the stream so we don't download the entire file. Sometimes, when running this check, after we close the stream, a write event occurs which tries to write to a stream that doesn't exist anymore, which crashes the server
transform: unknown so checking isImage, url= http://ftlabs-six-degrees.herokuapp.com/graph.html
events.js:141
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:159:12)
at Gunzip.Writable.write (_stream_writable.js:204:5)
at PassThrough.ondata (_stream_readable.js:528:20)
at emitOne (events.js:77:13)
at PassThrough.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at PassThrough.Readable.push (_stream_readable.js:110:10)
at PassThrough.Transform.push (_stream_transform.js:128:32)
at afterTransform (_stream_transform.js:76:12)
at TransformState.afterTransform (_stream_transform.js:54:12)
When we enter a URL that we can't immediately transform, we check whether or not it's an image by going to the URL, grabbing the first 8 bytes and checking the value of those bytes against a table of values that indicate an image and it's type (PNG/JPG etc.).
After we grab the first few bytes of the request, we close the stream so we don't download the entire file. Sometimes, when running this check, after we close the stream, a write event occurs which tries to write to a stream that doesn't exist anymore, which crashes the server