Skip to content

Commit

Permalink
fix(parcel-compressor-utf8): transformChunk with segment size 1024 (#967
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidp94 committed May 3, 2024
1 parent 232f0f0 commit cff4957
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/parcel-compressor-utf8/src/utf8-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ class Utf8Transform extends Transform {
remainder ? callback(null, this.transformChunk(remainder)) : callback()
}

private transformChunk(chunk: string): string {
return Array.from(chunk)
private transformChunk(chunk: string, segmentSize: number = 1024): string {
let result = ""
for (let i = 0; i < chunk.length; i += segmentSize) {
const endIndex = Math.min(i + segmentSize, chunk.length)
const segment = chunk.substring(i, endIndex)
result += this.transformSegment(segment)
}
return result
}

private transformSegment(segment: string): string {
return Array.from(segment)
.map((ch) =>
ch.charCodeAt(0) <= 0x7f
? ch
Expand Down

0 comments on commit cff4957

Please sign in to comment.