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

Unified Diff: tools/data_pack/data_pack.py

Issue 7604012: Remove the length field from the index entries in data pack files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix write 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
« no previous file with comments | « chrome/browser/themes/browser_theme_pack_unittest.cc ('k') | tools/grit/grit/format/data_pack.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/data_pack/data_pack.py
diff --git a/tools/data_pack/data_pack.py b/tools/data_pack/data_pack.py
index 571842eabea967f6d36f4200cbc1154b824ff236..ffd2cb2b0aa8639f52a4ea6ac5297f52a11a8a80 100755
--- a/tools/data_pack/data_pack.py
+++ b/tools/data_pack/data_pack.py
@@ -9,7 +9,7 @@ See base/pack_file* for details.
import struct
-FILE_FORMAT_VERSION = 2
+FILE_FORMAT_VERSION = 3
HEADER_LENGTH = 2 * 4 # Two uint32s. (file version and number of entries)
class WrongFileVersion(Exception):
@@ -26,13 +26,17 @@ def ReadDataPack(input_file):
raise WrongFileVersion
resources = {}
+ if num_entries == 0:
+ return resources
+
# Read the index and data.
data = data[HEADER_LENGTH:]
- kIndexEntrySize = 2 + 2 * 4 # Each entry is 1 uint16 and 2 uint32s.
+ kIndexEntrySize = 2 + 4 # Each entry is a uint16 and a uint32.
for _ in range(num_entries):
- id, offset, length = struct.unpack("<HII", data[:kIndexEntrySize])
+ id, offset = struct.unpack("<HI", data[:kIndexEntrySize])
data = data[kIndexEntrySize:]
- resources[id] = original_data[offset:offset + length]
+ next_id, next_offset = struct.unpack("<HI", data[:kIndexEntrySize])
+ resources[id] = original_data[offset:next_offset]
return resources
@@ -44,15 +48,18 @@ def WriteDataPack(resources, output_file):
# Write file header.
file.write(struct.pack("<II", FILE_FORMAT_VERSION, len(ids)))
- # Each entry is 1 uint16 and 2 uint32s.
- index_length = len(ids) * (2 + 2 * 4)
+ # Each entry is a uint16 and a uint32. We have one extra entry for the last
+ # item.
+ index_length = (len(ids) + 1) * (2 + 4)
# Write index.
data_offset = HEADER_LENGTH + index_length
for id in ids:
- file.write(struct.pack("<HII", id, data_offset, len(resources[id])))
+ file.write(struct.pack("<HI", id, data_offset))
data_offset += len(resources[id])
+ file.write(struct.pack("<HI", 0, data_offset))
+
# Write data.
for id in ids:
file.write(resources[id])
« no previous file with comments | « chrome/browser/themes/browser_theme_pack_unittest.cc ('k') | tools/grit/grit/format/data_pack.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698