877768d4aac0233bef65c32cbb8cb0d37151a23428f717444b2c2b71b39f1b062522d6ff8a3dc4432e3f63df66a55ae72957ec5525c89ce10278775f862bcb 549 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const fs = require('fs');
  3. const shebangCommand = require('shebang-command');
  4. function readShebang(command) {
  5. // Read the first 150 bytes from the file
  6. const size = 150;
  7. const buffer = Buffer.alloc(size);
  8. let fd;
  9. try {
  10. fd = fs.openSync(command, 'r');
  11. fs.readSync(fd, buffer, 0, size, 0);
  12. fs.closeSync(fd);
  13. } catch (e) { /* Empty */ }
  14. // Attempt to extract shebang (null is returned if not a shebang)
  15. return shebangCommand(buffer.toString());
  16. }
  17. module.exports = readShebang;