source: trip-planner-front/node_modules/cross-spawn/lib/util/readShebang.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 740 bytes
Line 
1'use strict';
2
3const fs = require('fs');
4const shebangCommand = require('shebang-command');
5
6function readShebang(command) {
7 // Read the first 150 bytes from the file
8 const size = 150;
9 let buffer;
10
11 if (Buffer.alloc) {
12 // Node.js v4.5+ / v5.10+
13 buffer = Buffer.alloc(size);
14 } else {
15 // Old Node.js API
16 buffer = new Buffer(size);
17 buffer.fill(0); // zero-fill
18 }
19
20 let fd;
21
22 try {
23 fd = fs.openSync(command, 'r');
24 fs.readSync(fd, buffer, 0, size, 0);
25 fs.closeSync(fd);
26 } catch (e) { /* Empty */ }
27
28 // Attempt to extract shebang (null is returned if not a shebang)
29 return shebangCommand(buffer.toString());
30}
31
32module.exports = readShebang;
Note: See TracBrowser for help on using the repository browser.