|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
549 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const fs = require('fs');
|
|---|
| 4 | const shebangCommand = require('shebang-command');
|
|---|
| 5 |
|
|---|
| 6 | function readShebang(command) {
|
|---|
| 7 | // Read the first 150 bytes from the file
|
|---|
| 8 | const size = 150;
|
|---|
| 9 | const buffer = Buffer.alloc(size);
|
|---|
| 10 |
|
|---|
| 11 | let fd;
|
|---|
| 12 |
|
|---|
| 13 | try {
|
|---|
| 14 | fd = fs.openSync(command, 'r');
|
|---|
| 15 | fs.readSync(fd, buffer, 0, size, 0);
|
|---|
| 16 | fs.closeSync(fd);
|
|---|
| 17 | } catch (e) { /* Empty */ }
|
|---|
| 18 |
|
|---|
| 19 | // Attempt to extract shebang (null is returned if not a shebang)
|
|---|
| 20 | return shebangCommand(buffer.toString());
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | module.exports = readShebang;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.