Long-time reader, first-time poster.
I am using node v0.6.6 on OS X 10.7. I have not yet tried this in any other environment. I am using this client: https://github.com/elbart/node-memcache
When I use the following code, data randomly contains a few more bytes (as reported by console.log()), which leads to this image: https://i.sstatic.net/MzOsw.jpg (and many other JPG do this). favicon seems OK and HTML/CSS/javascript all work.
In other words: if I request the image, ~70% of the time the image is returned correctly; the other 30% - data reports a few more bytes and the image appears corrupt in the browser.
client.get(key, function(err, data) {
if (err) throw err;
if (data) {
res.writeHead(200, {'Content-Type': type, 'Content-Length': data.length});
console.log('Sending with length: ' + data.length);
res.end(data, 'binary');
}
});
I have been messing with this for several hours and I can honestly say I am stumped. I am hoping someone can show me the error in my ways. I tried searching if there was a way to properly store binary data with memcache but there's no relevant information.
Extra information: it happens with various JPG images; all images are around 100-300KB or less in filesize. For example, one image has reported the following sizes: 286442, 286443, 286441. This problem DOES NOT occur if I straight read data from disk and serve it with node.
Thanks in advance.
Edit I updated my node version and issue persists. Actual test source photo and corrupt photo can be found in my comment below (stackoverflow doesn't permit more links).
vbindiffon the 2 files and here's where the corruption begins: i.imgur.com/gqTKW.png ... and the way its corrupt rules out my only idea. Might be a bug in memcache. I've never used it myself, I can suggest trying Redis or updating your Memcache if there's a new version. Sorry I couldn't be of more help!