fix: change method for alloc string to buffer (#777)

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.
Esse commit está contido em:
Lee, Jebum
2019-04-30 00:29:16 +09:00
commit de Wallace Breza
commit 90754dc74b
2 arquivos alterados com 2 adições e 1 exclusões
@@ -23,6 +23,7 @@ describe("LocalFileSystem Storage Provider", () => {
a: 1,
b: 2,
c: 3,
d: "한글 中國 にほんご",
};
await localFileSystem.writeText(filePath, JSON.stringify(contents, null, 4));
@@ -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);
}