Skip to content

Commit

Permalink
fix: Garbled encoding with two or more byte UTF-8 encoding filenames #93
Browse files Browse the repository at this point in the history


Full credit to @LasyLZ for this one
  • Loading branch information
quentinrossetti committed May 19, 2021
1 parent 801a79b commit ac91cd7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ const { LINE_SPLIT } = require('./regexp')
// When 7zip writes a progress value to stdout a new line is not created:
// Instead 7zip uses combination on backpaces and spaces char.
const fromBuffer = (seven, buffer) => {
const lines = buffer.toString().split(LINE_SPLIT)
if (seven._lastLinePartial) {
lines[0] = seven._lastLinePartial.concat(lines[0])
buffer = Buffer.concat([seven._lastLinePartial, buffer])
}
const newLastLine = lines[lines.length - 1]
const lines = buffer.toString().split(LINE_SPLIT)
const offset = buffer.lastIndexOf('\n') + 1
const newLastLine = buffer.slice(offset)
const isNewLastLineComplete = (newLastLine.indexOf('\n') === newLastLine.length - 1)

if (!isNewLastLineComplete) {
seven._lastLinePartial = newLastLine
lines.pop()
Expand Down

0 comments on commit ac91cd7

Please sign in to comment.