Skip to content

Commit

Permalink
Fixed bug of Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
syumai committed Dec 29, 2018
1 parent e747510 commit 30db9ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.json
14 changes: 8 additions & 6 deletions dpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ async function renderInternal(body: Reader, params: Params): Promise<Reader> {
return {
async read(p: Uint8Array): Promise<ReadResult> {
const len = p.byteLength;
let eof: boolean;
let nread: number;

for (nread = 0; nread < len; nread++) {
({ eof } = await src.read(readBuf));
const { eof } = await src.read(readBuf);
if (eof) {
break;
}
Expand Down Expand Up @@ -75,14 +74,15 @@ async function renderInternal(body: Reader, params: Params): Promise<Reader> {
continue;
}
if (buf.length > 2) {
p[nread] = buf.shift();
p[nread - 2] = buf.shift();
}
continue;
}

// Finish current ReadMode
if (buf[1] === Codes.Percent && buf[2] === Codes.End) {
statement.push(buf.shift());
nread--;
buf.splice(0);
// Don't execute if ReadMode is Comment.
if (readMode !== ReadMode.Comment) {
Expand All @@ -100,18 +100,20 @@ async function renderInternal(body: Reader, params: Params): Promise<Reader> {
}
statement.splice(0);
readMode = ReadMode.Normal;
nread -= 2;
nread -= 3;
continue;
}
statement.push(buf.shift());
nread--;
}

// Flush buffer
while (nread < len && buf.length > 0) {
p[nread] = buf.shift();
p[nread - 2] = buf.shift();
console.log(nread);
nread++;
}
return { nread, eof };
return { nread, eof: nread === 0 };
},
};
}
Expand Down

0 comments on commit 30db9ef

Please sign in to comment.