compression

How do I gzip compress a string in Python?

◇◆丶佛笑我妖孽 提交于 2019-11-26 12:41:43
问题 How do I gzip compress a string in Python? gzip.GzipFile exists, but that\'s for file objects - what about with plain strings? 回答1: If you want to produce a complete gzip-compatible binary string, with the header etc, you could use gzip.GzipFile together with StringIO: import StringIO import gzip out = StringIO.StringIO() with gzip.GzipFile(fileobj=out, mode="w") as f: f.write("This is mike number one, isn't this a lot of fun?") out.getvalue() # returns '\x1f\x8b\x08\x00\xbd\xbe\xe8N\x02\xff

How to compress a String in Java?

假装没事ソ 提交于 2019-11-26 12:39:42
问题 I use GZIPOutputStream or ZIPOutputStream to compress a String (my string.length() is less than 20), but the compressed result is longer than the original string. On some site, I found some friends said that this is because my original string is too short, GZIPOutputStream can be used to compress longer strings. so, can somebody give me a help to compress a String? My function is like: String compress(String original) throws Exception { } Update: import java.io.ByteArrayOutputStream; import

Best Compression algorithm for a sequence of integers

时间秒杀一切 提交于 2019-11-26 12:35:48
问题 I have a large array with a range of integers that are mostly continuous, eg 1-100, 110-160, etc. All integers are positive. What would be the best algorithm to compress this? I tried the deflate algorithm but that gives me only 50% compression. Note that the algorithm cannot be lossy. All numbers are unique and progressively increasing. Also if you can point me to the java implementation of such algorithm that would be great. 回答1: We have written recent research papers that survey the best

Java compressing Strings

隐身守侯 提交于 2019-11-26 12:29:38
问题 I need to create a method that receives a String and also returns a String. Ex input: AAABBBBCC Ex output: 3A4B2C Well, this is quite embarrassing and I couldn\'t manage to do it on the interview that I had today ( I was applying for a Junior position ), now, trying at home I made something that works statically, I mean, not using a loop which is kind of useless but I don\'t know if I\'m not getting enough hours of sleep or something but I can\'t figure it out how my for loop should look like

High quality JPEG compression with c#

为君一笑 提交于 2019-11-26 12:27:00
问题 I am using C# and want to save images using JPEG format. However .NET reduces quality of the images and saves them with compression that is not enough. I want to save files with their original quality and size. I am using the following code but compression and quality are not like the original ones. Bitmap bm = (Bitmap)Image.FromFile(FilePath); ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo ici = null; foreach (ImageCodecInfo codec in codecs) { if (codec.MimeType

How many times can a file be compressed?

一笑奈何 提交于 2019-11-26 12:06:36
问题 I was thinking about compression, and it seems like there would have to be some sort of limit to the compression that could be applied to it, otherwise it\'d be a single byte. So my question is, how many times can I compress a file before: It does not get any smaller? The file becomes corrupt? Are these two points the same or different? Where does the point of diminishing returns appear? How can these points be found? I\'m not talking about any specific algorithm or particular file, just in

Which is the best PHP method to reduce the image size without losing quality [closed]

爱⌒轻易说出口 提交于 2019-11-26 12:00:43
问题 I am trying to develop an image based web site. I am really confused about the image type and compression techniques. Please advice me the best way to compress image sizes. 回答1: I'd go for jpeg . Read this post regarding image size reduction and after deciding on the technique, use ImageMagick Hope this helps 回答2: If you are looking to reduce the size using coding itself, you can follow this code in php. <?php function compress($source, $destination, $quality) { $info = getimagesize($source);

Which compression method to use in PHP?

风流意气都作罢 提交于 2019-11-26 11:59:16
问题 I have a large amount of data to move using two PHP scripts: one on the client side using a command line PHP script and other behind Apache. I POST the data to the server side and use php://input stream to save it on the web-server end. To prevent from reaching any memory limits, data is separated into 500kB chunks for each POST request. All this works fine. Now, to save the bandwidth and speed it up, I want to compress the data before sending and decompress when received on the other end. I

What is a good Java library to zip/unzip files? [closed]

喜夏-厌秋 提交于 2019-11-26 11:30:37
I looked at the default Zip library that comes with the JDK and the Apache compression libs and I am unhappy with them for 3 reasons: They are bloated and have bad API design. I have to write 50 lines of boiler plate byte array output, zip input, file out streams and close relevant streams and catch exceptions and move byte buffers on my own ? Why can't I have a simple API that looks like this Zipper.unzip(InputStream zipFile, File targetDirectory, String password = null) and Zipper.zip(File targetDirectory, String password = null) that just works? It seems zipping unzipping destroys file meta

How to use the 7z SDK to compress and decompress a file

梦想的初衷 提交于 2019-11-26 11:12:49
问题 According to this link How do I create 7-Zip archives with .NET? , WOPR tell us how to compress a file with LMZA (7z compression algorithm) using 7z SDK ( http://www.7-zip.org/sdk.html ) using SevenZip.Compression.LZMA; private static void CompressFileLZMA(string inFile, string outFile) { SevenZip.Compression.LZMA.Encoder coder = new SevenZip.Compression.LZMA.Encoder(); using (FileStream input = new FileStream(inFile, FileMode.Open)) { using (FileStream output = new FileStream(outFile,