Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
fix: change method for alloc string to buffer (#777)
Browse files Browse the repository at this point in the history
String.length is not appropriate for calculating buffer size
when non-alphabet letter is included in content.
Change the method Buffer.alloc to Buffer.from as directed by the nodejs document.
  • Loading branch information
golee authored and wbreza committed Apr 29, 2019
1 parent bae8338 commit dba3130
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/electron/providers/storage/localFileSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("LocalFileSystem Storage Provider", () => {
a: 1,
b: 2,
c: 3,
d: "한글 中國 にほんご",
};

await localFileSystem.writeText(filePath, JSON.stringify(contents, null, 4));
Expand Down
2 changes: 1 addition & 1 deletion src/electron/providers/storage/localFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class LocalFileSystem implements IStorageProvider {
}

public writeText(filePath: string, contents: string): Promise<void> {
const buffer = Buffer.alloc(contents.length, contents);
const buffer = Buffer.from(contents);
return this.writeBinary(filePath, buffer);
}

Expand Down

0 comments on commit dba3130

Please sign in to comment.