Skip to content

Commit

Permalink
stop reading only when 0 bytes that been read, #37541
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 14, 2017
1 parent 5fd4061 commit 33acfb5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/vs/workbench/services/files/node/fileService.ts
Expand Up @@ -414,15 +414,16 @@ export class FileService implements IFileService {

const handleChunk = (bytesRead) => {
if (token.isCancellationRequested) {
// cancellation
// cancellation -> finish
finish(new Error('cancelled'));

} else if (bytesRead === 0) {
// no more data -> finish
finish();
} else if (bytesRead < chunkBuffer.length) {
// done, write rest, end
decoder.write(chunkBuffer.slice(0, bytesRead), finish);

// write the sub-part of data we received -> repeat
decoder.write(chunkBuffer.slice(0, bytesRead), readChunk);
} else {
// read, write, repeat
// write all data we received -> repeat
decoder.write(chunkBuffer, readChunk);
}
};
Expand Down

0 comments on commit 33acfb5

Please sign in to comment.