Sha256: a751b45841a6786f9ae8ea6c12de6ea761332863bcf4224f5342af6bcedc6615

Contents?: true

Size: 740 Bytes

Versions: 73

Compression:

Stored size: 740 Bytes

Contents

'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;

Version data entries

73 entries across 71 versions & 11 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack-cli/node_modules/cross-spawn/lib/util/readShebang.js
optimacms-0.1.61 spec/dummy/node_modules/execa/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.18.0 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.18.2 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.16.1 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.15.2 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.18.4 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.18.1 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.14.0 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/cross-spawn/lib/util/readShebang.js
tang-0.2.1 spec/tang_app/node_modules/cross-spawn/lib/util/readShebang.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/cross-spawn/lib/util/readShebang.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/cross-spawn/lib/util/readShebang.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/cross-spawn/lib/util/readShebang.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/cross-spawn/lib/util/readShebang.js
tang-0.2.0 spec/tang_app/node_modules/cross-spawn/lib/util/readShebang.js
tang-0.1.0 spec/tang_app/node_modules/cross-spawn/lib/util/readShebang.js
tang-0.0.9 spec/tang_app/node_modules/cross-spawn/lib/util/readShebang.js
enju_library-0.3.8 spec/dummy/node_modules/cross-spawn/lib/util/readShebang.js