1

python programmers, I'm am new to python ,I read that we have built in functions to achieve file compression in python . I just wanted to know if a file compression can be done without using these built in functions (maybe a longer code perhaps) .I wanted to understand the working of these built in functions(how they are coded) basically . forgive the fallacies(if any) of a beginner, thanks in advance

1
  • Read about data compression, as internally, the python source code will implement gzip, zip, zlib, and bz2 algorithms. In the real world, though, use the standard modules - they are worked on constantly, improved with new versions, heavily used and tested. Commented Dec 3, 2010 at 18:40

2 Answers 2

2

Well there are lots of different ways to compress data, but it can be quite a task to undertake. One area you might want to research is Huffman Coding which can help with compression, especially for plain text. The reason I point it out is that it is more approachable than other compression techniques, and can be a good starting point.

Sure it is possible to do on your own, but it will be much longer than using pre-built functions and probably not as effective.

If you want to look up the implementation you can find open source libraries and look over the code that actually implements various compression algorithms.

Researching and learning about the code is a great idea, but unless there is a very good reason not to you should stick to using the pre-built modules.

Sign up to request clarification or add additional context in comments.

Comments

1

If you would like to learn more about how file compression works, the code is available right in the python source code in the file gzip.py. You should also check out the zlib source code, on which the gzip module is based.

You can get zlib source code from zlib.net.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.