Skip to content

Instantly share code, notes, and snippets.

@painkkiller
Forked from energizer91/getFileSize.js
Created June 28, 2018 08:43
Show Gist options
  • Save painkkiller/5b2a8cfb15943cc4e945921654c754ab to your computer and use it in GitHub Desktop.
Save painkkiller/5b2a8cfb15943cc4e945921654c754ab 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