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

Unified Diff: tools/data_pack/data_pack.py

Issue 7744017: Updated *.pak file format to support both UTF8 and UTF16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up comments/ Created 9 years, 4 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
Index: tools/data_pack/data_pack.py
diff --git a/tools/data_pack/data_pack.py b/tools/data_pack/data_pack.py
index ffd2cb2b0aa8639f52a4ea6ac5297f52a11a8a80..7059dea47b427ef3c0f917af74339940f564f4f4 100755
--- a/tools/data_pack/data_pack.py
+++ b/tools/data_pack/data_pack.py
@@ -9,8 +9,12 @@ See base/pack_file* for details.
import struct
-FILE_FORMAT_VERSION = 3
-HEADER_LENGTH = 2 * 4 # Two uint32s. (file version and number of entries)
+FILE_FORMAT_VERSION = 4
+HEADER_LENGTH = 3 * 4 # Three uint32s. (file version, number of entries and
+ # encoding of text resources)
tony 2011/08/29 21:24:39 Can we use something smaller than an uint32 for th
marcvs 2011/08/30 07:58:55 Changed to uint8 (== unsigned char).
+BINARY = 0
+UTF8 = 1
+UTF16 = 2
tony 2011/08/29 21:24:39 BINARY, UTF8, UTF16 = range(3)
marcvs 2011/08/30 07:58:55 Done. (also in the other files)
class WrongFileVersion(Exception):
pass
@@ -21,13 +25,14 @@ def ReadDataPack(input_file):
original_data = data
# Read the header.
- version, num_entries = struct.unpack("<II", data[:HEADER_LENGTH])
+ version, num_entries, encoding = struct.unpack("<III", data[:HEADER_LENGTH])
if version != FILE_FORMAT_VERSION:
+ print "Wrong file version in ", input_file
raise WrongFileVersion
resources = {}
if num_entries == 0:
- return resources
+ return resources, encoding
# Read the index and data.
data = data[HEADER_LENGTH:]
@@ -38,15 +43,15 @@ def ReadDataPack(input_file):
next_id, next_offset = struct.unpack("<HI", data[:kIndexEntrySize])
resources[id] = original_data[offset:next_offset]
- return resources
+ return resources, encoding
-def WriteDataPack(resources, output_file):
+def WriteDataPack(resources, output_file, encoding):
"""Write a map of id=>data into output_file as a data pack."""
ids = sorted(resources.keys())
file = open(output_file, "wb")
# Write file header.
- file.write(struct.pack("<II", FILE_FORMAT_VERSION, len(ids)))
+ file.write(struct.pack("<III", FILE_FORMAT_VERSION, len(ids), encoding))
# Each entry is a uint16 and a uint32. We have one extra entry for the last
# item.
@@ -67,9 +72,9 @@ def WriteDataPack(resources, output_file):
def main():
# Just write a simple file.
data = { 1: "", 4: "this is id 4", 6: "this is id 6", 10: "" }
- WriteDataPack(data, "datapack1.pak")
+ WriteDataPack(data, "datapack1.pak", UTF8)
data2 = { 1000: "test", 5: "five" }
- WriteDataPack(data2, "datapack2.pak")
+ WriteDataPack(data2, "datapack2.pak", UTF8)
print "wrote datapack1 and datapack2 to current directory."
if __name__ == '__main__':

Powered by Google App Engine
This is Rietveld 408576698