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

Unified Diff: tools/data_pack/DataPack.py

Issue 17402: Python library for writing data pack files (see base/data_pack*). (Closed)
Patch Set: Created 11 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/data_pack/DataPack.py
diff --git a/tools/data_pack/DataPack.py b/tools/data_pack/DataPack.py
new file mode 100755
index 0000000000000000000000000000000000000000..c269f21c7fd5170a262b3050e3c697f23f195958
--- /dev/null
+++ b/tools/data_pack/DataPack.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
tony 2009/01/08 00:44:53 Nit: this file should be named data_pack.py or som
+# 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: "" }
tony 2009/01/08 00:44:53 Maybe include some embedded nulls?
+ WriteDataPack(data, "datapack")
+ print "wrote datapack to current directory."
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698