Coder Social home page Coder Social logo

lz4-ts's Introduction

lz4-ts

This is a TypeScript port of https://github.com/pierrec/lz4.

function calcUncompressedLen(src: Uint8Array): number;
function uncompressBlock(src: Uint8Array, dest: Uint8Array): number;
function compressBlockBound(n: number): number;
function compressBlock(src: Uint8Array, dest: Uint8Array, soffset: number): number;
function compressBlockHC(src: Uint8Array, dest: Uint8Array, soffset: number): number;

LICENSE

Copyright (c) 2015, Pierre Curto
Copyright (c) 2016, oov
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of xxHash nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

lz4-ts's People

Contributors

oov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lz4-ts's Issues

Uncompression failure in the library

Hello,
Recently I decided to write a usdz parser in typescript , as the file format got popular since AR popularization.
As part of project I used lz4-ts , for uncompression but the following strange issue came up.
I calculate uncompressed buffer size using calcUncompressedLen , and it works very well , actually usdc file contains the uncompressed buffer size and I use calcUncompressedLen to make sure its value is correct. But when I call uncompressBlock on the compressed data , I get 'short buffer' error. I event tried to create a buffer with very larger than expected uncompressed buffer length , but the issue remained.

Issue reproduce:

const carr = [244,90,112,114,105,109,67,104,105,108,100,114,101,110,0,103,114,97,109,111,112,104,111,110,101,0,117,112,65,120,105,115,0,89,0,109,101,116,101,114,115,80,101,114,85,110,105,116,0,100,101,102,97,117,108,116,80,114,105,109,0,116,105,109,101,67,111,100,101,115,80,101,114,83,101,99,111,110,100,0,99,117,115,116,111,109,76,97,121,101,114,68,97,116,97,0,99,111,112,121,114,105,103,104,116,0,67,10,0,241,10,32,40,99,41,32,50,48,49,57,32,65,112,112,108,101,32,73,110,99,46,32,65,108,108,32,40,0,244,28,115,32,114,101,115,101,114,118,101,100,46,0,99,114,101,97,116,111,114,0,85,83,68,32,49,57,46,48,53,32,77,97,121,97,32,80,108,117,103,105,110,32,40,63,0,245,23,116,101,114,110,97,108,32,97,51,41,0,0,115,112,101,99,105,102,105,101,114,0,116,121,112,101,78,97,109,101,0,88,102,111,114,109,0,71,218,0,207,83,117,112,112,111,114,116,70,111,111,116,49,23,0,3,31,50,23,0,3,31,51,23,0,3,23,52,23,0,136,66,111,120,69,120,116,114,97,89,0,4,20,0,8,86,0,4,20,0,8,83,0,4,20,0,8,80,0,104,82,101,99,111,114,100,78,0,2,18,0,8,76,0,2,18,0,8,74,0,2,18,0,8,72,0,152,72,111,114,110,69,108,98,111,119,75,0,5,21,0,8,78,0,5,21,0,8,81,0,0,21,0,10,230,0,72,66,111,100,121,18,0,167,97,99,107,66,114,97,99,107,101,116,22,0,168,82,101,112,114,111,100,117,99,101,114,119,0,6,22,0,8,120,0,183,67,114,97,110,107,72,97,110,100,108,101,66,0,1,22,0,7,16,0,58,78,101,101,33,0,151,68,105,115,99,76,101,118,101,114,37,0,0,20,0,240,31,80,108,97,116,116,101,114,0,76,111,111,107,115,0,107,105,110,100,0,99,111,109,112,111,110,101,110,116,0,77,101,115,104,0,112,114,111,112,101,114,116,105,101,115,0,120,34,2,244,3,79,112,58,116,114,97,110,115,108,97,116,101,58,112,105,118,111,116,24,0,240,13,79,114,100,101,114,0,100,111,117,98,108,101,83,105,100,101,100,0,112,111,105,110,116,115,0,101,120,116,79,0,208,102,97,99,101,86,101,114,116,101,120,67,111,117,24,0,6,17,0,240,19,73,110,100,105,99,101,115,0,115,117,98,100,105,118,105,115,105,111,110,83,99,104,101,109,101,0,110,111,114,109,97,108,115,0,127,3,120,118,97,114,115,58,115,116,12,0,35,58,105,58,0,5,32,0,240,8,100,105,115,112,108,97,121,67,111,108,111,114,0,109,97,116,101,114,105,97,108,58,98,40,0,240,10,110,103,0,83,99,111,112,101,0,112,120,114,85,115,100,80,114,101,118,105,101,119,83,117,114,137,0,83,49,83,71,0,77,47,0,7,37,1,5,19,0,81,102,105,108,101,53,6,0,17,55,6,0,17,52,6,0,17,54,6,0,178,56,0,111,117,116,112,117,116,115,58,115,77,0,64,0,83,104,97,13,1,117,105,110,102,111,58,105,100,31,0,2,157,0,48,99,101,109,16,1,33,105,110,51,0,114,100,105,102,102,117,115,101,177,0,3,20,0,132,109,101,116,97,108,108,105,99,16,0,2,6,1,4,14,0,80,111,99,99,108,117,36,1,4,17,0,176,114,111,117,103,104,110,101,115,115,0,84,93,1,81,111,114,100,82,101,128,0,4,151,0,52,114,103,98,44,0,21,115,121,0,0,204,0,4,22,0,132,102,97,108,108,98,97,99,107,16,0,64,118,97,114,110,21,4,5,65,0,85,101,115,117,108,116,200,0,244,3,114,0,98,111,111,108,0,118,97,114,105,97,98,105,108,105,116,121,241,4,253,7,0,102,108,111,97,116,51,91,93,0,105,110,116,91,93,0,116,111,107,101,110,0,110,1,2,18,0,1,211,1,2,171,0,17,95,56,0,16,50,24,0,176,85,86,84,101,120,116,117,114,101,0,99,197,1,242,3,51,102,0,99,111,110,110,101,99,116,105,111,110,80,97,116,104,115,100,0,166,52,0,97,115,115,101,116,0,48,47,142,5,122,95,98,99,46,112,110,103,20,0,30,110,19,0,30,109,19,0,30,114,19,0,33,97,111,20,0,1,154,0,3,137,2,34,51,102,125,0,178,50,0,115,116,0,116,97,114,103,101,116,147,0,2,162,1,34,51,102,249,0,96,101,114,112,111,108,97,177,0,16,0,92,2,84,86,97,114,121,105,74,0,18,51,23,3,1,43,0,3,225,0,35,91,93,17,6,1,12,6,0,189,5,163,0,103,101,110,101,114,97,116,101,100,112,0,65,91,93,0,118,60,3,32,0,110,118,6,1,87,1,96,91,93,0,33,105,110,23,0,31,33,155,3,5,6,78,6,71,50,48,50,49,74,6,128,10,10,80,101,114,109,105,115,71,2,240,15,32,105,115,32,104,101,114,101,98,121,32,103,114,97,110,116,101,100,44,32,102,114,101,101,32,111,102,32,99,104,229,0,240,13,44,32,116,111,32,97,110,121,32,112,101,114,115,111,110,32,111,98,116,97,105,110,105,110,103,32,97,32,187,6,0,42,0,240,9,116,104,105,115,32,115,111,102,116,119,97,114,101,32,97,110,100,32,97,115,115,111,99,105,197,0,80,32,100,111,99,117,245,2,1,20,1,16,32,122,2,147,115,32,40,116,104,101,32,34,83,50,0,33,34,41,101,0,128,100,101,97,108,32,105,110,32,28,0,4,27,0,128,32,119,105,116,104,111,117,116,243,6,49,116,114,105,9,2,112,44,32,105,110,99,108,117,213,3,5,31,0,67,108,105,109,105,98,0,0,63,0,3,40,7,113,116,111,32,117,115,101,44,168,0,193,44,32,109,111,100,105,102,121,44,32,109,101,215,0,240,7,112,117,98,108,105,115,104,44,32,100,105,115,116,114,105,98,117,116,101,44,32,115,21,0,48,99,101,110,54,0,176,97,110,100,47,111,114,32,115,101,108,108,66,0,50,105,101,115,236,0,6,158,0,1,36,0,0,32,1,16,112,81,1,19,116,35,1,1,120,0,74,119,104,111,109,202,0,177,105,115,32,102,117,114,110,105,115,104,101,52,0,81,100,111,32,115,111,114,0,64,106,101,99,116,18,0,0,91,0,96,102,111,108,108,111,119,95,1,80,99,111,110,100,105,72,2,208,115,58,10,10,84,104,101,32,97,98,111,118,101,138,0,17,121,223,0,98,32,110,111,116,105,99,111,1,1,129,1,1,133,0,2,214,1,3,27,0,131,115,104,97,108,108,32,98,101,49,1,32,101,100,95,1,0,19,0,4,207,0,16,114,241,0,144,115,116,97,110,116,105,97,108,32,244,7,16,105,192,0,1,211,1,6,231,0,240,101,46,10,10,84,72,69,32,83,79,70,84,87,65,82,69,32,73,83,32,80,82,79,86,73,68,69,68,32,34,65,83,32,73,83,34,44,32,87,73,84,72,79,85,84,32,87,65,82,82,65,78,84,89,32,79,70,32,65,78,89,32,75,73,78,68,44,32,69,88,80,82,69,83,83,32,79,82,32,73,77,80,76,73,69,68,44,32,73,78,67,76,85,68,73,78,71,32,66,85,84,32,78,79,84,32,76,73,77,73,84,69,68,32,84,79,32,113,0,3,75,0,48,73,69,83,77,0,241,84,77,69,82,67,72,65,78,84,65,66,73,76,73,84,89,44,32,70,73,84,78,69,83,83,32,70,79,82,32,65,32,80,65,82,84,73,67,85,76,65,82,32,80,85,82,80,79,83,69,32,65,78,68,32,78,79,78,73,78,70,82,73,78,71,69,77,69,78,84,46,32,73,78,32,78,79,32,69,86,69,78,84,32,83,72,65,76,76,32,84,72,69,32,65,85,84,72,79,82,160,0,242,12,67,79,80,89,82,73,71,72,84,32,72,79,76,68,69,82,83,32,66,69,32,76,73,65,66,76,69,107,0,240,0,78,89,32,67,76,65,73,77,44,32,68,65,77,65,71,158,0,113,82,32,79,84,72,69,82,39,0,3,158,0,49,87,72,69,19,0,192,73,78,32,65,78,32,65,67,84,73,79,78,199,0,229,67,79,78,84,82,65,67,84,44,32,84,79,82,84,59,0,240,5,87,73,83,69,44,32,65,82,73,83,73,78,71,32,70,82,79,77,44,32,79,1,32,79,70,35,0,130,73,78,32,67,79,78,78,69,70,0,0,107,1,1,182,0,5,146,1,33,79,82,16,0,33,85,83,11,0,2,140,0,128,68,69,65,76,73,78,71,83,242,0,0,78,1,176,83,79,70,84,87,65,82,69,46,10];
const cbuffer = new Uint8Array(carr);
const usize = calcUncompressedLen(cbuffer);
console.info('buffer',usize);
const ubuffer = new Uint8Array(usize);
const usize2 = uncompressBlock(cbuffer,ubuffer );
console.log(usize2)

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.