def write_crx_as_xpi(chunks, storage, target):
 temp_crx_file = tempfile.mkstemp()[1]
 with storage.open(temp_crx_file, 'rwb+') as temp_file:
  for chunk in chunks:
   temp_file.write(chunk)
  temp_file.seek(0)
  header = temp_file.read(16)
  header_info = struct.unpack('4cHxII', header)
  public_key_length = header_info[5]
  signature_length = header_info[6]
  start_position = ((16 + public_key_length) + signature_length)
  hash = hashlib.sha256()
  temp_file.seek(start_position)
  with storage.open(target, 'wb') as file_destination:
   bytes = temp_file.read(65536)
   while bytes:
    hash.update(bytes)
    file_destination.write(bytes)
    bytes = temp_file.read(65536)
 return hash

def write_crx_as_xpi ( chunks , storage , target ) : temp_crx_file = tempfile . mkstemp ( ) [ 1 ] with storage . open ( temp_crx_file , 'rwb+' ) as temp_file : for chunk in chunks : temp_file . write ( chunk ) temp_file . seek ( 0 ) header = temp_file . read ( 16 ) header_info = struct . unpack ( '4cHxII' , header ) public_key_length = header_info [ 5 ] signature_length = header_info [ 6 ] start_position = ( ( 16 + public_key_length ) + signature_length ) hash = hashlib . sha256 ( ) temp_file . seek ( start_position ) with storage . open ( target , 'wb' ) as file_destination : bytes = temp_file . read ( 65536 ) while bytes : hash . update ( bytes ) file_destination . write ( bytes ) bytes = temp_file . read ( 65536 ) return hash
extract and strip the header from the crx .