aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/detect-libc/lib/filesystem.js
diff options
context:
space:
mode:
authorpack <pack@packgekko.xyz>2026-08-09 10:37:07 +0000
committerpack <pack@packgekko.xyz>2026-08-09 10:37:07 +0000
commit55a4f1fc869e41aca748c63d3018f0448b1606e0 (patch)
treed132d1d01772b6d53faee3e63c534dea5706b78a /node_modules/detect-libc/lib/filesystem.js
downloadcrud-55a4f1fc869e41aca748c63d3018f0448b1606e0.tar.gz
first commit
Diffstat (limited to 'node_modules/detect-libc/lib/filesystem.js')
-rw-r--r--node_modules/detect-libc/lib/filesystem.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/node_modules/detect-libc/lib/filesystem.js b/node_modules/detect-libc/lib/filesystem.js
new file mode 100644
index 0000000..4c2443c
--- /dev/null
+++ b/node_modules/detect-libc/lib/filesystem.js
@@ -0,0 +1,51 @@
+// Copyright 2017 Lovell Fuller and others.
+// SPDX-License-Identifier: Apache-2.0
+
+'use strict';
+
+const fs = require('fs');
+
+const LDD_PATH = '/usr/bin/ldd';
+const SELF_PATH = '/proc/self/exe';
+const MAX_LENGTH = 2048;
+
+/**
+ * Read the content of a file synchronous
+ *
+ * @param {string} path
+ * @returns {Buffer}
+ */
+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);
+};
+
+/**
+ * Read the content of a file
+ *
+ * @param {string} path
+ * @returns {Promise<Buffer>}
+ */
+const readFile = (path) => new Promise((resolve, reject) => {
+ fs.open(path, 'r', (err, fd) => {
+ if (err) {
+ reject(err);
+ } else {
+ const buffer = Buffer.alloc(MAX_LENGTH);
+ fs.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
+ resolve(buffer.subarray(0, bytesRead));
+ fs.close(fd, () => {});
+ });
+ }
+ });
+});
+
+module.exports = {
+ LDD_PATH,
+ SELF_PATH,
+ readFileSync,
+ readFile
+};