Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 2667180

Browse files
committed
Refactor serializeBuffer()
1 parent 8cbd3a6 commit 2667180

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/buffer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
2-
* stringifyBuffer() converts the provided buffer to the same JSON string that would result if converted with
3-
* JSON.stringify(). Instead of calling buf.toJSON() and then stringifying the result, the buffer values are
4-
* concatenated with a preexisting string that matches what would be returned by JSON.stringify().
2+
* Converts the provided buffer to the same JSON string that would result if converted with JSON.stringify(). Instead
3+
* of calling toJSON() and then stringifying the result, the buffer values are concatenated with a pre-prepared string
4+
* that matches the output of JSON.stringify().
55
*/
66

7-
export function stringifyBuffer(buf: Buffer): string {
7+
export function serializeBuffer(buf: Buffer): string {
88
let str = '{"type":"Buffer","data":[';
9+
let i;
910
let prefix = '';
1011

11-
for (let i = 0; i < buf.length; i++) {
12+
for (i = 0; i < buf.length; i++) {
1213
str += prefix + buf[i];
1314
prefix = ',';
1415
}

0 commit comments

Comments
 (0)