Urara-Blog/node_modules/.pnpm-store/v3/files/b1/3f95761bcee8520f90fc60b12780fc9e564c181be76cf89f4ae3eb0bb329e0f45cee6970ebf020e509162eae1cb1e787e2b44b8778a5727235a8b9d1bc68c1
2022-08-14 01:14:53 +08:00

32 lines
740 B
Text

'use strict';
const fs = require('fs');
const shebangCommand = require('shebang-command');
function readShebang(command) {
// Read the first 150 bytes from the file
const size = 150;
let buffer;
if (Buffer.alloc) {
// Node.js v4.5+ / v5.10+
buffer = Buffer.alloc(size);
} else {
// Old Node.js API
buffer = new Buffer(size);
buffer.fill(0); // zero-fill
}
let fd;
try {
fd = fs.openSync(command, 'r');
fs.readSync(fd, buffer, 0, size, 0);
fs.closeSync(fd);
} catch (e) { /* Empty */ }
// Attempt to extract shebang (null is returned if not a shebang)
return shebangCommand(buffer.toString());
}
module.exports = readShebang;