git-essentials icon indicating copy to clipboard operation
git-essentials copied to clipboard

Update Pako library to the latest version

Open alex-titarenko opened this issue 3 years ago • 1 comments

Apparently Pako v2.* has some breaking changes that prevent us from updating it without deep investigation.

Problematic code in this library: https://github.com/NotesHubApp/git-essentials/blob/d793ac5c74091f9bd4546c6a92fe56c9eff167b7/src/utils/git-list-pack.ts#L48-L51

Problematic code on pako library: https://github.com/nodeca/pako/blob/174a1d12b68dfbd531a572eaaea0937491b36f55/lib/inflate.js#L237-L245

// Skip snyc markers if more data follows and not raw mode
while (strm.avail_in > 0 &&
       status === Z_STREAM_END &&
       strm.state.wrap > 0 &&
       data[strm.next_in] !== 0)
{
  zlib_inflate.inflateReset(strm);
  status = zlib_inflate.inflate(strm, _flush_mode);
}

this does not exist in Pako v1.* and causes the following error in Inflator Err: -3, msg: 'incorrect header check'

alex-titarenko avatar Sep 19 '22 12:09 alex-titarenko

Since CompressionStream API is not available in stable Safari we should consider instead upgrading code to use native API

async function browserInflate(buffer: Uint8Array) {
  const ds = new DecompressionStream('deflate')
  const d = (<ReadableStream><unknown>new Blob([buffer]).stream()).pipeThrough(ds)
  return new Uint8Array(await new Response(d).arrayBuffer())
}

alex-titarenko avatar Mar 30 '23 01:03 alex-titarenko