Files
appco_dist/.output/server/node_modules/detect-libc/lib/filesystem.js
T

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-01-27 16:47:33 +03:30
// Copyright 2017 Lovell Fuller and others.
// SPDX-License-Identifier: Apache-2.0
'use strict';
const fs = require('fs');
const LDD_PATH = '/usr/bin/ldd';
2026-02-01 17:38:39 +03:30
const SELF_PATH = '/proc/self/exe';
const MAX_LENGTH = 2048;
2026-01-27 16:47:33 +03:30
/**
* Read the content of a file synchronous
*
* @param {string} path
2026-02-01 17:38:39 +03:30
* @returns {Buffer}
2026-01-27 16:47:33 +03:30
*/
2026-02-01 17:38:39 +03:30
const readFileSync = (path) => {
const fd = fs.openSync(path, 'r');
const buffer = Buffer.alloc(MAX_LENGTH);
const bytesRead = fs.readSync(fd, buffer, 0, MAX_LENGTH, 0);
fs.close(fd, () => {});
return buffer.subarray(0, bytesRead);
};
2026-01-27 16:47:33 +03:30
/**
* Read the content of a file
*
* @param {string} path
2026-02-01 17:38:39 +03:30
* @returns {Promise<Buffer>}
2026-01-27 16:47:33 +03:30
*/
const readFile = (path) => new Promise((resolve, reject) => {
2026-02-01 17:38:39 +03:30
fs.open(path, 'r', (err, fd) => {
2026-01-27 16:47:33 +03:30
if (err) {
reject(err);
} else {
2026-02-01 17:38:39 +03:30
const buffer = Buffer.alloc(MAX_LENGTH);
fs.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
resolve(buffer.subarray(0, bytesRead));
fs.close(fd, () => {});
});
2026-01-27 16:47:33 +03:30
}
});
});
module.exports = {
LDD_PATH,
2026-02-01 17:38:39 +03:30
SELF_PATH,
2026-01-27 16:47:33 +03:30
readFileSync,
readFile
};