Skip to content

Commit 64f1fa1

Browse files
authored
feat: read the release assets asynchronously (#552)
Previously all assets were being read synchronously into memory, making the action unsuitable for releasing very large assets. Because the client library allows stream body inputs (it just forwards it to the underlying `fetch` implementation), just do it. The idea is also suggested by @enumag in #353 (comment). Fixes: #353 Signed-off-by: WANG Xuerui <[email protected]>
1 parent 9e35a64 commit 64f1fa1

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

__tests__/github.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//import * as assert from "assert";
2-
//const assert = require('assert');
31
import * as assert from "assert";
2+
import { text } from "stream/consumers";
43
import { mimeOrDefault, asset } from "../src/github";
54

65
describe("github", () => {
@@ -19,7 +18,7 @@ describe("github", () => {
1918
assert.equal(name, "bar.txt");
2019
assert.equal(mime, "text/plain");
2120
assert.equal(size, 10);
22-
assert.equal(data.toString(), "release me");
21+
assert.equal(await text(data), "release me");
2322
});
2423
});
2524
});

src/github.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GitHub } from "@actions/github/lib/utils";
22
import { Config, isTag, releaseBody, alignAssetName } from "./util";
3-
import { statSync, readFileSync } from "fs";
3+
import { createReadStream, statSync, type ReadStream } from "fs";
44
import { getType } from "mime";
55
import { basename } from "path";
66

@@ -10,7 +10,7 @@ export interface ReleaseAsset {
1010
name: string;
1111
mime: string;
1212
size: number;
13-
data: Buffer;
13+
data: ReadStream;
1414
}
1515

1616
export interface Release {
@@ -145,7 +145,7 @@ export const asset = (path: string): ReleaseAsset => {
145145
name: basename(path),
146146
mime: mimeOrDefault(path),
147147
size: statSync(path).size,
148-
data: readFileSync(path),
148+
data: createReadStream(path, "binary"),
149149
};
150150
};
151151

0 commit comments

Comments
 (0)