MCPcopy Index your code
hub / github.com/microsoft/vscode-languageserver-node / append

Method append

jsonrpc/src/messageReader.ts:31–51  ·  view source on GitHub ↗
(chunk: Buffer | String)

Source from the content-addressed store, hash-verified

29 }
30
31 public append(chunk: Buffer | String): void {
32 var toAppend: Buffer = <Buffer>chunk;
33 if (typeof (chunk) == 'string') {
34 var str = <string>chunk;
35 var bufferLen = Buffer.byteLength(str, this.encoding);
36 toAppend = new Buffer(bufferLen);
37 toAppend.write(str, 0, bufferLen, this.encoding);
38 }
39 if (this.buffer.length - this.index >= toAppend.length) {
40 toAppend.copy(this.buffer, this.index, 0, toAppend.length);
41 } else {
42 var newSize = (Math.ceil((this.index + toAppend.length) / DefaultSize) + 1) * DefaultSize;
43 if (this.index === 0) {
44 this.buffer = new Buffer(newSize);
45 toAppend.copy(this.buffer, 0, 0, toAppend.length);
46 } else {
47 this.buffer = Buffer.concat([this.buffer.slice(0, this.index), toAppend], newSize);
48 }
49 }
50 this.index += toAppend.length;
51 }
52
53 public tryReadHeaders(): { [key: string]: string; } | undefined {
54 let result: { [key: string]: string; } | undefined = undefined;

Callers 2

onDataMethod · 0.80

Calls 1

writeMethod · 0.65

Tested by

no test coverage detected