a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(lex-cli): improve how LSP messages are processed

Mary c789d3ee 20227546

+8 -7
+8 -7
packages/lexicons/lex-cli/src/lsp-client.ts
··· 148 148 }; 149 149 150 150 // incremental message parser 151 - let buffer = Buffer.alloc(0); 151 + const HEADER_SEPARATOR = Buffer.from('\r\n\r\n'); 152 + 153 + let buffer: Buffer = Buffer.alloc(0); 152 154 let contentLength = -1; 153 - const HEADER_SEPARATOR = Buffer.from('\r\n\r\n'); 154 155 155 156 const processBuffer = (): void => { 156 157 while (true) { ··· 160 161 break; 161 162 } 162 163 163 - const header = buffer.subarray(0, separatorIndex).toString(); 164 + const header = buffer.toString('utf8', 0, separatorIndex); 164 165 const match = header.match(/Content-Length:\s*(\d+)/i); 165 166 167 + buffer = buffer.subarray(separatorIndex + 4); 168 + 166 169 if (!match) { 167 - buffer = buffer.subarray(separatorIndex + 4); 168 170 continue; 169 171 } 170 172 171 173 contentLength = parseInt(match[1], 10); 172 - buffer = buffer.subarray(separatorIndex + 4); 173 174 } 174 175 175 176 if (buffer.length < contentLength) { 176 177 break; 177 178 } 178 179 179 - const body = buffer.subarray(0, contentLength).toString(); 180 + const body = buffer.toString('utf8', 0, contentLength); 180 181 buffer = buffer.subarray(contentLength); 181 182 contentLength = -1; 182 183 ··· 204 205 }; 205 206 206 207 child.stdout.on('data', (chunk: Buffer) => { 207 - buffer = Buffer.concat([buffer, chunk]); 208 + buffer = buffer.length > 0 ? Buffer.concat([buffer, chunk]) : chunk; 208 209 processBuffer(); 209 210 }); 210 211