@ts-graphviz/adapter 3.0.8 → 3.0.9
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/CHANGELOG.md +6 -0
- package/lib/node.js +29 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ts-graphviz/adapter
|
|
2
2
|
|
|
3
|
+
## 3.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1768](https://github.com/ts-graphviz/ts-graphviz/pull/1768) [`0d478f7`](https://github.com/ts-graphviz/ts-graphviz/commit/0d478f79dfab21c440dc0c7239f0b2aa7256677d) Thanks [@kamiazya](https://github.com/kamiazya)! - `toFile` opens the output file and writes it with positional arguments only, without an options object, so the whole output always replaces the file at the given path.
|
|
8
|
+
|
|
3
9
|
## 3.0.8
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/lib/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { pipeline } from "node:stream/promises";
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
3
2
|
import { spawn } from "node:child_process";
|
|
4
3
|
import { PassThrough, Readable } from "node:stream";
|
|
4
|
+
import { pipeline } from "node:stream/promises";
|
|
5
5
|
import { createCommandAndArgs } from "./create-command-and-args.js";
|
|
6
6
|
async function toStream(dot, options) {
|
|
7
7
|
const [command, args] = createCommandAndArgs(options ?? {});
|
|
@@ -54,13 +54,33 @@ function ownEnv() {
|
|
|
54
54
|
}
|
|
55
55
|
async function toFile(dot, path, options) {
|
|
56
56
|
const stream = await toStream(dot, options);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
let handle;
|
|
58
|
+
try {
|
|
59
|
+
handle = await open(path, "w");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
stream.destroy();
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
for await (const chunk of stream) {
|
|
66
|
+
const buffer = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
67
|
+
let offset = 0;
|
|
68
|
+
while (offset < buffer.length) {
|
|
69
|
+
const { bytesWritten } = await handle.write(
|
|
70
|
+
buffer,
|
|
71
|
+
offset,
|
|
72
|
+
buffer.length - offset
|
|
73
|
+
);
|
|
74
|
+
offset += bytesWritten;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
stream.destroy();
|
|
79
|
+
await handle.close().catch(() => {
|
|
80
|
+
});
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
await handle.close();
|
|
64
84
|
}
|
|
65
85
|
export {
|
|
66
86
|
toFile,
|