While trying to learn to use Node filestreams, I wrote a few test apps that fetched images from remote servers and saved them to disk. Problem is, while some of the test images downloaded fine, others failed in a bizarre way without returning errors and writing only 400 to 460 bytes of 100+ kB images. Here you can see nautilus showing a successful download on the left and a failed partial download that never threw any errors on the right. The partial downloads are always in the 400 to 460 byte range.
Here's the sample code I'm using for my tests; some images downloaded fine, others download partially and throw no errors:
var
express = require( 'express' )
, app = express.createServer()
, request = require( 'request' )
, fs = require( 'fs' )
, url = 'http://static.designspiration.net/data/assets/012311-010912AM_158289.jpg';
app.get( '/', function( req, res){
request( url, function( err ){
if( err ){ console.log( err ); }
}).pipe( fs.createWriteStream( './Downloads/testimage.jpg' ) );
});
app.listen( 8083 );
Anyone have any clue what's going on?