Skip to content

Instantly share code, notes, and snippets.

@energizer91
Last active June 28, 2018 08:43
Show Gist options
  • Save energizer91/ce99be797992c7924392f2476a7d239d to your computer and use it in GitHub Desktop.
Save energizer91/ce99be797992c7924392f2476a7d239d to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
app.post('/file', (req, res, next) => {
let first = true;
req.on('data', chunk => {
if (!first) {
return;
}
console.log('file extension is', chunk.slice(1, 4).toString());
console.log('PNG width is', chunk.readUIntBE(16, 4));
console.log('PNG height is', chunk.readUIntBE(20, 4));
first = false;
});
req.on('end', () => {
res.send('done');
})
req.on('error', next);
});
app.use((err, req, res, next) => {
res.send('error' + JSON.stringify(err));
});
app.listen('3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment