Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect decoding when parsing an archive with a file with Cyrillic characters #260

Open
grdvsng opened this issue Aug 22, 2022 · 2 comments

Comments

@grdvsng
Copy link

grdvsng commented Aug 22, 2022

I'm use archive with only one file with 5000K content length.

main test:

import { createReadStream } from 'fs';
import * as path from 'path';
import * as unzipper from 'unzipper';

import { checkInvalideByte } from '../string-helper';

jest.setTimeout(1000 * 30);

const TEST_ARCHIVE_PATH = path.join(
  __dirname,
  './mock_data/archive-with-russian-chars.zip',
);

describe('archive-with-cyrillic -chars', () => {
  describe('unzipper lib test', () => {
    it('should incorrect decode when use readable stream', async () => {
      const stream = createReadStream(TEST_ARCHIVE_PATH);
      const ended = new Promise((resolve, reject) => {
        stream.on('end', resolve);
        stream.on('error', reject);

        const unzipStream = unzipper.ParseOne();

        unzipStream.on('data', (chunk) => {
          const line = chunk.toString();

          checkInvalideByte(line).catch(reject);
        });

        stream.pipe(unzipStream);
      });

      await expect(ended).rejects.toThrow();
    });
  });
});

string-helper.ts

export function checkInvalideByte(content: string): Promise<void> {
  return new Promise((resolve, reject) => {
    const splited = content.split('\n');

    for (let i = 0; i < splited.length; i += 1) {
      const line = splited[i];
      const column = line.indexOf('�');

      if (column >= 0) {
        const text = `Invalide byte decoded at line: ${i + 1} column: ${
          column + 1
        } ('${line.slice(column - 10, column + 1)}')`;

        reject(new Error(text));
      }
    }

    resolve();
  });
}
@luisbajana
Copy link

Hey, @grdvsng did you solve it? I'm having the same problem.

@grdvsng
Copy link
Author

grdvsng commented Nov 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants