Coder Social home page Coder Social logo

Zlib support about kobopatch HOT 6 CLOSED

pgaskin avatar pgaskin commented on May 20, 2024
Zlib support

from kobopatch.

Comments (6)

pgaskin avatar pgaskin commented on May 20, 2024

The hard part about this is figuring out a consistent and concise way to read and patch the zlib strings.

from kobopatch.

pgaskin avatar pgaskin commented on May 20, 2024

So far, I have this: https://gist.github.com/geek1011/55ca3c4e750aa1bcd497cf296ceb8cf0 , which works for extracting the css. The biggest issue is that when recompressing it, the go zlib library uses a different dict (0x8c instead of 0x8d). Once I can get it to use the proper dict, I'll be able to add it to kobopatch and implement find_zlib, replace_zlib and replace_css instructions.

from kobopatch.

pgaskin avatar pgaskin commented on May 20, 2024

Some notes I've made for myself:

kobo      : 1111000 10011100 10001101 10010100 1011111 1101111
            78      9c       8d       94       5f      6f
czlib (go): 1111000 10011100 10001100 10010100 1011111 1101111
            78      9c       8c       94       5f      6f
go stdlib is completely wrong, so I'm using the czlib library instead.
            CMF---- FLG----- DICTID --------------------------

CMF:
 - Deflate compression

FLG:
 - Uses FDICT
 - Default compression (level 6)

DICTID:
 - TODO: figure out what the dictionary is (inconsistent between czlib and kobo).
         if it comes to it, I might just fork out to python, which uses the correct dict

References:
 - https://stackoverflow.com/questions/9050260/what-does-a-zlib-header-look-like
 - https://tools.ietf.org/html/rfc1950

from kobopatch.

pgaskin avatar pgaskin commented on May 20, 2024

I think I might just end up embedding (if I can get it to cross-compile to a static binary or execing python (at least for now). Figuring out the compression issue is getting to be a bit too much work. The other alternative might be to use cgo to run a c program which calls zlib.

from kobopatch.

pgaskin avatar pgaskin commented on May 20, 2024

Nevermind, 😠 I missed something obvious again (just like path chars in kepubify)!

Internally, python uses zlib.compressobj for zlib.compress. This uses deflateInit2. When I used czlib, I used czlib.NewWriterLevel, which internally uses deflateInit, which is different. To fix this, all I had to do was call czlib.Compress instead.

Now, I just need to do some more testing, then this feature should be ready!

from kobopatch.

pgaskin avatar pgaskin commented on May 20, 2024

New gist: https://gist.github.com/geek1011/ac32378471be5c0334cff09567fcd057

from kobopatch.

Related Issues (20)

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.