Archived
1
0

Fix coping and moving files around using the file tree (#568)

* Implement write/read buffers in electron fill

This makes cutting and copy files from the file tree work.

* Implement fs.createReadStream

This is used by the file tree to copy files.

* Allow passing proxies back from client to server

This makes things like piping streams possible.

* Synchronously bind to proxy events

This eliminates any chance whatsoever of missing events due to binding
too late.

* Make it possible to bind some events on demand

* Add some protocol documentation
This commit is contained in:
Asher
2019-04-24 10:38:21 -05:00
committed by GitHub
parent 30b8565e2d
commit c9f91e77cd
21 changed files with 546 additions and 278 deletions

View File

@ -10,7 +10,7 @@ describe("child_process", () => {
const cp = client.modules[Module.ChildProcess];
const getStdout = async (proc: ChildProcess): Promise<string> => {
return new Promise((r): Readable => proc.stdout!.on("data", r))
return new Promise((r): Readable => proc.stdout!.once("data", r))
.then((s) => s.toString());
};

View File

@ -131,6 +131,42 @@ describe("fs", () => {
});
});
describe("createReadStream", () => {
it("should read a file", async () => {
const file = helper.tmpFile();
const content = "foobar";
await util.promisify(nativeFs.writeFile)(file, content);
const reader = fs.createReadStream(file);
await expect(new Promise((resolve, reject): void => {
let data = "";
reader.once("error", reject);
reader.once("end", () => resolve(data));
reader.on("data", (d) => data += d.toString());
})).resolves.toBe(content);
});
it("should pipe to a writable stream", async () => {
const source = helper.tmpFile();
const content = "foo";
await util.promisify(nativeFs.writeFile)(source, content);
const destination = helper.tmpFile();
const reader = fs.createReadStream(source);
const writer = fs.createWriteStream(destination);
await new Promise((resolve, reject): void => {
reader.once("error", reject);
writer.once("error", reject);
writer.once("close", resolve);
reader.pipe(writer);
});
await expect(util.promisify(nativeFs.readFile)(destination, "utf8")).resolves.toBe(content);
});
});
describe("exists", () => {
it("should output file exists", async () => {
await expect(util.promisify(fs.exists)(__filename))
@ -279,10 +315,9 @@ describe("fs", () => {
.resolves.toBeUndefined();
});
// TODO: Doesn't fail on my system?
it("should fail to lchown nonexistent file", async () => {
await expect(util.promisify(fs.lchown)(helper.tmpFile(), 1, 1))
.resolves.toBeUndefined();
.rejects.toThrow("ENOENT");
});
});