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

Unified Diff: tools/grit/grit/node/include.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/gzip_string_unittest.py ('k') | tools/grit/grit/node/include_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/node/include.py
diff --git a/tools/grit/grit/node/include.py b/tools/grit/grit/node/include.py
index 4780d5e8425b475a5956028bbcfd832b3dd29c05..39e226e7ff97d084094b571dcb50ab60a4259252 100755
--- a/tools/grit/grit/node/include.py
+++ b/tools/grit/grit/node/include.py
@@ -7,16 +7,21 @@
"""
import os
+import sys
+from grit import exception
+from grit import util
+import grit.format.gzip_string
import grit.format.html_inline
-import grit.format.rc_header
import grit.format.rc
-
+import grit.format.rc_header
from grit.node import base
-from grit import util
class IncludeNode(base.Node):
"""An <include> element."""
+
+ RESERVED_HEADER = '\xff\x1f\x8b'
+
def __init__(self):
super(IncludeNode, self).__init__()
@@ -38,7 +43,6 @@ class IncludeNode(base.Node):
preprocess_only=False,
allow_external_script=allow_external_script))
return self._flattened_data
-
def MandatoryAttributes(self):
return ['name', 'type', 'file']
@@ -48,6 +52,7 @@ class IncludeNode(base.Node):
'filenameonly': 'false',
'mkoutput': 'false',
'flattenhtml': 'false',
+ 'compress': 'false',
'allowexternalscript': 'false',
'relativepath': 'false',
'use_base_dir': 'true',
@@ -91,6 +96,23 @@ class IncludeNode(base.Node):
filename = self.ToRealPath(self.GetInputPath())
data = util.ReadFile(filename, util.BINARY)
+ if 'compress' in self.attrs and self.attrs['compress'] == 'gzip':
+ # We only use rsyncable compression on Linux.
+ if sys.platform == 'linux2':
+ data = grit.format.gzip_string.GzipStringRsyncable(data)
+ else:
+ data = grit.format.gzip_string.GzipString(data)
+ data = self.RESERVED_HEADER[0] + data
+ elif data[:3] == self.RESERVED_HEADER:
+ # We are reserving these 3 bytes as the header for gzipped files in the
+ # data pack. 1f:8b is the first two bytes of a gzipped header, and ff is
+ # a custom byte we throw in front of the gzip header so that we prevent
+ # accidentally throwing this error on a resource we gzipped beforehand and
+ # don't wish to compress again. If this exception is hit, change the first
+ # byte of RESERVED_HEADER, and then mirror that update in
+ # ui/base/resource/resource_bundle.h
+ raise exception.ReservedHeaderCollision();
+
# Include does not care about the encoding, because it only returns binary
# data.
return id, data
« no previous file with comments | « tools/grit/grit/format/gzip_string_unittest.py ('k') | tools/grit/grit/node/include_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698