pkggzip.py revision 461
461N/A#!/usr/bin/python
461N/A#
461N/A# CDDL HEADER START
461N/A#
461N/A# The contents of this file are subject to the terms of the
461N/A# Common Development and Distribution License (the "License").
461N/A# You may not use this file except in compliance with the License.
461N/A#
461N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
461N/A# or http://www.opensolaris.org/os/licensing.
461N/A# See the License for the specific language governing permissions
461N/A# and limitations under the License.
461N/A#
461N/A# When distributing Covered Code, include this CDDL HEADER in each
461N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
461N/A# If applicable, add the following below this CDDL HEADER, with the
461N/A# fields enclosed by brackets "[]" replaced with your own identifying
461N/A# information: Portions Copyright [yyyy] [name of copyright owner]
461N/A#
461N/A# CDDL HEADER END
461N/A#
461N/A
461N/A#
461N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
461N/A# Use is subject to license terms.
461N/A#
461N/A#ident "%Z%%M% %I% %E% SMI"
461N/A
461N/Aimport sys
461N/Aimport struct
461N/Aimport gzip
461N/A
461N/Adef out32u(outf, val):
461N/A outf.write(struct.pack("<L", val))
461N/A
461N/Aclass PkgGzipFile(gzip.GzipFile):
461N/A """This is a version of GzipFile that does not include a file
461N/A pathname or timestamp in the gzip header. This allows us to get
461N/A deterministic gzip files on compression, so that we can reliably
461N/A use a cryptopgraphic hash on the compressed content."""
461N/A
461N/A def __init__(self, filename=None, mode=None, compresslevel=9,
461N/A fileobj=None):
461N/A
461N/A gzip.GzipFile.__init__(self, filename, mode, compresslevel,
461N/A fileobj)
461N/A
461N/A def _write_gzip_header(self):
461N/A self.fileobj.write("\037\213")
461N/A self.fileobj.write("\010")
461N/A self.fileobj.write(chr(0))
461N/A out32u(self.fileobj, long(0))
461N/A self.fileobj.write("\002")
461N/A self.fileobj.write("\377")