gzip

Writing GZIP file with nio

北慕城南 提交于 2019-12-25 05:15:44
问题 This is my code: WritableByteChannel channel = null; GZIPOutputStream out = null; try { channel = Channels.newChannel(new FileOutputStream("C:\\temp\\111.zip")); out = new GZIPOutputStream(Channels.newOutputStream(channel)); for (long i = 0; i < 10000000000; i++) { out.write(("string" + i + "\n").getBytes()); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (channel != null) { channel.close(); } } catch (Exception e) { } try { if (out != null) { out.close(); } } catch

How can I compress a char array into a compressed html page using Zlib

北城余情 提交于 2019-12-25 04:04:43
问题 I have a CGI application in C that creates an html page by saving a char* as a html page: void saveTextFile(const char *filename, const char *str){.......} called as saveTextFile("..\\index.html",outputFile); How do I use zlib to take as input the "outputFile" char array and output a zipped html page with appropriate headers? Would the gzopen be used here instead of my saveTextFile function? Any advice is appreciated. Thanks. 回答1: Got it - //***************************************************

Rails/Ruby invalid byte sequence in UTF-8 even after force_encoding

早过忘川 提交于 2019-12-25 03:45:28
问题 I'm trying to iterate over a remote nginx log file (compressed .gz file) in Rails and I'm getting this error at some point in the file: TTPArgumentError: invalid byte sequence in UTF-8 I tried forcing the encoding too although it seems the encoding was already UTF8: logfile = logfile.force_encoding("UTF-8") The method that I'm using: def remote_update uri = "http://" + self.url + "/localhost.access.log.2.gz" source = open(uri) gz = Zlib::GzipReader.new(source) logfile = gz.read # prints UTF-8

How to uncompress .xml.gz in windows?

若如初见. 提交于 2019-12-25 03:19:34
问题 I wrote a script to generate the sitemaps for my website, and then compress the files to .gz. Everything seems to be ok, since google can read the urls from the files. But when I download them by accessing them through the corresponding url in the production enviroment (linux), and then open them with winrar (in my local pc), I get garbage, like it was a binary file or something. The same thing works fine in my development enviroment (windows), so it seems to be an OS-dependant thing. Any

using gzip compression with webpack and express, still serving bundle.js instead of bundle.js.gz

一曲冷凌霜 提交于 2019-12-25 03:17:38
问题 I've just installed and setup gzip compression to my webpack and express files. The plugins snippet of my webpack.config.js now looks like this: plugins: [ new webpack.DefinePlugin({ // <-- key to reducing React's size 'process.env': { 'NODE_ENV': JSON.stringify('production') } }), new webpack.optimize.UglifyJsPlugin(), //minify everything new webpack.optimize.AggressiveMergingPlugin(),//Merge chunks new CompressionPlugin({ asset: "[path].gz[query]", algorithm: "gzip", test: /\.js$|\.css$|\

Check if GZIP file exists in Python

拟墨画扇 提交于 2019-12-25 03:14:18
问题 I would like to check for the existence of a .gz file on my linux machine while running Python. If I do this for a text file, the following code works: import os.path os.path.isfile('bob.asc') However, if bob.asc is in gzip format (bob.asc.gz), Python does not recognize it. Ideally, I would like to use os.path.isfile or something very concise (without writing new functions). Is it possible to make the file recognizable either in Python or by changing something in my system configuration?

Cannot Compress Java Server Response Sent To JSP

早过忘川 提交于 2019-12-24 15:13:11
问题 I am having trouble in returning compressed response (GZip) from my Java Servlet, to a JSP. Flow : Request comes to java servlet Process the request, and create a JSON object, with the response Convert the JSON object to string Compress the response string with GZip The compressed response string is set as attribute in the request object and control passed to JSP In the JSP, the response string (compressed) is printed on screen Precautions : Request object has "Accepting-Encoding" set with

PHP can't decompress gzip data by Golang

隐身守侯 提交于 2019-12-24 13:45:24
问题 Why can't decompress gzip data by Go in my PHP demo, but PHP gzip data to Go is successful? I need post gzip JSON data from Go to PHP API service. Test result -> | php | go --------------------- php | ok | ok go | fail | ok PHP code class GzipDemo { public function gzen($data, $file){ $json_data = json_encode($data); $gz_data = gzencode($json_data,9); file_put_contents($file,$gz_data); } public function gzdn($file){ $data = file_get_contents($file); $unpacked = gzdecode($data); if ($unpacked

Minify & Gzip vs Google CDN

早过忘川 提交于 2019-12-24 11:52:07
问题 Should I minify/gzip my Jquery with my other scripts on my page, or use Google CDN for Jquery & JQuery UI and gzip my own stuff. From what I can see its more likely to be faster to deliver from Google and there is a better chance the files will be cached already on the users machine, however its a couple of extra http request and at least I know it will always be available. 回答1: You got it right. For widely-used librairies, using Google CDN is a good idea: uses less bandwith on your server

Minify & Gzip vs Google CDN

試著忘記壹切 提交于 2019-12-24 11:48:07
问题 Should I minify/gzip my Jquery with my other scripts on my page, or use Google CDN for Jquery & JQuery UI and gzip my own stuff. From what I can see its more likely to be faster to deliver from Google and there is a better chance the files will be cached already on the users machine, however its a couple of extra http request and at least I know it will always be available. 回答1: You got it right. For widely-used librairies, using Google CDN is a good idea: uses less bandwith on your server