forked from Mirror/attic-action
fix: use StringStream
This commit is contained in:
parent
5dc7b671af
commit
e0114a9f15
4 changed files with 23 additions and 16 deletions
|
@ -19,3 +19,4 @@ runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
post: "dist/post.js"
|
post: "dist/post.js"
|
||||||
|
post-if: "success()"
|
||||||
|
|
4
dist/index.js
vendored
4
dist/index.js
vendored
File diff suppressed because one or more lines are too long
4
dist/post.js
vendored
4
dist/post.js
vendored
File diff suppressed because one or more lines are too long
30
src/utils.ts
30
src/utils.ts
|
@ -1,21 +1,27 @@
|
||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
import { Writable } from "node:stream";
|
import { Writable } from "node:stream";
|
||||||
|
|
||||||
const streamToString = (stream: Writable): Promise<string> => {
|
class StringStream extends Writable {
|
||||||
const chunks: Buffer[] = [];
|
chunks: Buffer[] = [];
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
_write(
|
||||||
stream.on("error", (err) => reject(err));
|
chunk: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
|
||||||
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
_enc: unknown,
|
||||||
});
|
next: () => unknown
|
||||||
};
|
) {
|
||||||
|
this.chunks.push(Buffer.from(chunk));
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
string() {
|
||||||
|
return Buffer.concat(this.chunks).toString("utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getStorePaths = async () => {
|
export const getStorePaths = async () => {
|
||||||
const outStream = new Writable();
|
const outStream = new StringStream();
|
||||||
await exec("nix", ["path-info", "--all"], { outStream });
|
await exec("nix", ["path-info", "--all"], { outStream });
|
||||||
const paths = await streamToString(outStream)
|
const paths = outStream.string().split("\n").filter(Boolean);
|
||||||
.then((res) => res.split("\n"))
|
|
||||||
.then((paths) => paths.filter(Boolean));
|
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue