utilitas 1989.9.36 → 1989.9.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/storage.mjs +14 -0
- package/package.json +1 -1
package/lib/storage.mjs
CHANGED
|
@@ -98,6 +98,19 @@ const assertPath = async (path, type, mode, message, status = 500, options = {})
|
|
|
98
98
|
return stat;
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
const isTextFile = async (filename, options) => {
|
|
102
|
+
let [fh, result] = [await fs.promises.open(filename, 'r'), true];
|
|
103
|
+
for (var i = 0; i < ~~options?.length || 1000; i++) {
|
|
104
|
+
const buf = Buffer.alloc(1);
|
|
105
|
+
const bytes = fs.readSync(fh.fd, buf, 0, 1, i);
|
|
106
|
+
if (bytes === 0) { break; } else if (
|
|
107
|
+
bytes === 1 && buf.toString().charCodeAt() === 0
|
|
108
|
+
) { result = false; break; }
|
|
109
|
+
}
|
|
110
|
+
fh.close()
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
113
|
+
|
|
101
114
|
const getConfigFilename = async (options) => {
|
|
102
115
|
options = options || {};
|
|
103
116
|
const file = options.config || path.join(os.homedir(
|
|
@@ -155,6 +168,7 @@ export {
|
|
|
155
168
|
exists,
|
|
156
169
|
getConfig,
|
|
157
170
|
getConfigFilename,
|
|
171
|
+
isTextFile,
|
|
158
172
|
legalFilename,
|
|
159
173
|
readIni,
|
|
160
174
|
readJson,
|