inibase 1.0.0-rc.34 → 1.0.0-rc.35
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/dist/file.js +4 -11
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/file.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { open, access, writeFile, readFile, constants as fsConstants, unlink, } from "node:fs/promises";
|
|
1
|
+
import { open, access, writeFile, readFile, constants as fsConstants, unlink, stat, } from "node:fs/promises";
|
|
2
2
|
import { createInterface } from "node:readline";
|
|
3
3
|
import { Transform } from "node:stream";
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
@@ -367,7 +367,7 @@ export const replace = async (filePath, replacements) => {
|
|
|
367
367
|
*/
|
|
368
368
|
export const append = async (filePath, data) => {
|
|
369
369
|
const fileTempPath = filePath.replace(/([^/]+)\/?$/, `.tmp/$1`);
|
|
370
|
-
if (await isExists(filePath)) {
|
|
370
|
+
if ((await isExists(filePath)) && (await stat(filePath)).size) {
|
|
371
371
|
let fileHandle, fileTempHandle, rl;
|
|
372
372
|
try {
|
|
373
373
|
fileHandle = await open(filePath, "r");
|
|
@@ -406,25 +406,18 @@ export const append = async (filePath, data) => {
|
|
|
406
406
|
* Note: Creates a temporary file during the process and replaces the original file with it after removing lines.
|
|
407
407
|
*/
|
|
408
408
|
export const remove = async (filePath, linesToDelete) => {
|
|
409
|
-
let linesCount = 0
|
|
409
|
+
let linesCount = 0;
|
|
410
410
|
const fileHandle = await open(filePath, "r"), fileTempPath = filePath.replace(/([^/]+)\/?$/, `.tmp/$1`), fileTempHandle = await open(fileTempPath, "w"), linesToDeleteArray = new Set(Array.isArray(linesToDelete)
|
|
411
411
|
? linesToDelete.map(Number)
|
|
412
412
|
: [Number(linesToDelete)]), rl = readLineInternface(fileHandle);
|
|
413
413
|
await _pipeline(rl, fileTempHandle.createWriteStream(), new Transform({
|
|
414
414
|
transform(line, encoding, callback) {
|
|
415
415
|
linesCount++;
|
|
416
|
-
if (linesToDeleteArray.has(linesCount))
|
|
417
|
-
deletedCount++;
|
|
416
|
+
if (linesToDeleteArray.has(linesCount))
|
|
418
417
|
return callback();
|
|
419
|
-
}
|
|
420
418
|
else
|
|
421
419
|
return callback(null, `${line}\n`);
|
|
422
420
|
},
|
|
423
|
-
final(callback) {
|
|
424
|
-
if (deletedCount === linesCount)
|
|
425
|
-
this.push("\n");
|
|
426
|
-
return callback();
|
|
427
|
-
},
|
|
428
421
|
}));
|
|
429
422
|
await fileTempHandle.close();
|
|
430
423
|
await fileHandle.close();
|
package/dist/index.js
CHANGED
|
@@ -958,7 +958,7 @@ export default class Inibase {
|
|
|
958
958
|
if (!Array.isArray(columns))
|
|
959
959
|
columns = [columns];
|
|
960
960
|
for await (const column of columns) {
|
|
961
|
-
const columnPath = join(
|
|
961
|
+
const columnPath = join(tablePath, column + ".inib");
|
|
962
962
|
if (await File.isExists(columnPath)) {
|
|
963
963
|
if (where) {
|
|
964
964
|
const lineNumbers = await this.get(tableName, where, undefined, undefined, true, schema);
|
|
@@ -982,7 +982,7 @@ export default class Inibase {
|
|
|
982
982
|
if (!Array.isArray(columns))
|
|
983
983
|
columns = [columns];
|
|
984
984
|
for await (const column of columns) {
|
|
985
|
-
const columnPath = join(
|
|
985
|
+
const columnPath = join(tablePath, column + ".inib");
|
|
986
986
|
if (await File.isExists(columnPath)) {
|
|
987
987
|
if (where) {
|
|
988
988
|
const lineNumbers = await this.get(tableName, where, undefined, undefined, true, schema);
|
|
@@ -1006,7 +1006,7 @@ export default class Inibase {
|
|
|
1006
1006
|
if (!Array.isArray(columns))
|
|
1007
1007
|
columns = [columns];
|
|
1008
1008
|
for await (const column of columns) {
|
|
1009
|
-
const columnPath = join(
|
|
1009
|
+
const columnPath = join(tablePath, column + ".inib");
|
|
1010
1010
|
if (await File.isExists(columnPath)) {
|
|
1011
1011
|
if (where) {
|
|
1012
1012
|
const lineNumbers = await this.get(tableName, where, undefined, undefined, true, schema);
|