Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: tools/grit/grit/format/gzip_string.py

Issue 1968993002: Compressing .pak resources with new option: "type=GZIPPABLE_BINDATA" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Python formatting Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/grit/grit/format/data_pack_unittest.py ('k') | tools/grit/grit/format/gzip_string_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/gzip_string.py
diff --git a/tools/grit/grit/format/gzip_string.py b/tools/grit/grit/format/gzip_string.py
new file mode 100644
index 0000000000000000000000000000000000000000..4f54aac1da04c5803e28d74aa4e211f67048c8a7
--- /dev/null
+++ b/tools/grit/grit/format/gzip_string.py
@@ -0,0 +1,43 @@
+# Copyright (c) 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Provides gzip utilities for strings.
+"""
+import cStringIO
+import gzip
+import subprocess
+
+
+def GzipStringRsyncable(data):
+ # Make call to host system's gzip to get access to --rsyncable option. This
+ # option makes updates much smaller - if one line is changed in the resource,
+ # it won't have to push the entire compressed resource with the update.
+ # Instead, --rsyncable breaks the file into small chunks, so that one doesn't
+ # affect the other in compression, and then only that chunk will have to be
+ # updated.
+ gzip_proc = subprocess.Popen(['gzip', '--stdout', '--rsyncable',
+ '--best', '--no-name'],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ data, stderr = gzip_proc.communicate(data)
+ if gzip_proc.returncode != 0:
+ raise subprocess.CalledProcessError(gzip_proc.returncode, 'gzip',
+ stderr)
+ return data
+
+
+def GzipString(data):
+ # Gzipping using Python's built in gzip: Windows doesn't ship with gzip, and
+ # OSX's gzip does not have an --rsyncable option built in. Although this is
+ # not preferable to --rsyncable, it is an option for the systems that do
+ # not have --rsyncable. If used over GzipStringRsyncable, the primary
+ # difference of this function's compression will be larger updates every time
+ # a compressed resource is changed.
+ gzip_output = cStringIO.StringIO()
+ with gzip.GzipFile(mode='wb', compresslevel=9, fileobj=gzip_output,
+ mtime=0) as gzip_file:
+ gzip_file.write(data)
+ data = gzip_output.getvalue()
+ gzip_output.close()
+ return data
« no previous file with comments | « tools/grit/grit/format/data_pack_unittest.py ('k') | tools/grit/grit/format/gzip_string_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698