summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 01:00:16 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 01:00:16 +0000
commit9162a11c97dd8f1a8a701f5ce04905b0cf41991e (patch)
tree9b05a212e5ca89a01b2c5522768e7ef819ab15c4 /tools
parentbd04abd493a296e9309fca99d23530b3493ddc93 (diff)
downloadchromium_src-9162a11c97dd8f1a8a701f5ce04905b0cf41991e.zip
chromium_src-9162a11c97dd8f1a8a701f5ce04905b0cf41991e.tar.gz
chromium_src-9162a11c97dd8f1a8a701f5ce04905b0cf41991e.tar.bz2
Python library for writing data pack files (see base/data_pack*).
Review URL: http://codereview.chromium.org/17402 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7709 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rwxr-xr-xtools/data_pack/data_pack.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/data_pack/data_pack.py b/tools/data_pack/data_pack.py
new file mode 100755
index 0000000..c269f21
--- /dev/null
+++ b/tools/data_pack/data_pack.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+# Copyright (c) 2008 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.
+
+"""A simple utility function to produce data pack files.
+See base/pack_file* for details.
+"""
+
+import struct
+
+version = 1
+
+def WriteDataPack(resources, output_file):
+ """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", version, len(ids)))
+ header_length = 2 * 4 # Two uint32s.
+
+ index_length = len(ids) * 3 * 4 # Each entry is 3 uint32s.
+
+ # Write index.
+ data_offset = header_length + index_length
+ for id in ids:
+ file.write(struct.pack("<III", id, data_offset, len(resources[id])))
+ data_offset += len(resources[id])
+
+ # Write data.
+ for id in ids:
+ file.write(resources[id])
+
+def main():
+ # Just write a simple file.
+ data = { 1: "", 4: "this is id 4", 6: "this is id 6", 10: "" }
+ WriteDataPack(data, "datapack")
+ print "wrote datapack to current directory."
+
+if __name__ == '__main__':
+ main()