def extractFile(self, filename):
files = [x for x in self.tableOfContents if x['<STR_LIT:filename>'] == filename]<EOL>if len(files) == <NUM_LIT:0>:<EOL><INDENT>raise FileNotFoundException()<EOL><DEDENT>fileRecord = files[<NUM_LIT:0>]<EOL>metaheadroom = <NUM_LIT>  <EOL>request = urllib.request.Request(self.zipURI)<EOL>start = fileRecord['<STR_LIT>']<EOL>end = fileRecord['<STR_LIT>'] + fileRecord['<STR_LIT>'] + metaheadroom<EOL>request.headers['<STR_LIT>'] = "<STR_LIT>" % (start, end)<EOL>handle = urllib.request.urlopen(request)<EOL>return_range = handle.headers.get('<STR_LIT>')<EOL>if return_range != "<STR_LIT>" % (start, end, self.filesize):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>filedata = handle.read()<EOL>zip_n = unpack("<STR_LIT:H>", filedata[<NUM_LIT>:<NUM_LIT>])[<NUM_LIT:0>]<EOL>zip_m = unpack("<STR_LIT:H>", filedata[<NUM_LIT>:<NUM_LIT:30>])[<NUM_LIT:0>]<EOL>has_data_descriptor = bool(unpack("<STR_LIT:H>", filedata[<NUM_LIT:6>:<NUM_LIT:8>])[<NUM_LIT:0>] & <NUM_LIT:8>)<EOL>comp_size = unpack("<STR_LIT:I>", filedata[<NUM_LIT>:<NUM_LIT>])[<NUM_LIT:0>]<EOL>if comp_size == <NUM_LIT:0> and has_data_descriptor:<EOL><INDENT>comp_size = fileRecord['<STR_LIT>']<EOL><DEDENT>elif comp_size != fileRecord['<STR_LIT>']:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>raw_zip_data = filedata[<NUM_LIT:30> + zip_n + zip_m: <NUM_LIT:30> + zip_n + zip_m + comp_size]<EOL>uncompressed_data = "<STR_LIT>"<EOL>compression_method = unpack("<STR_LIT:H>", filedata[<NUM_LIT:8>:<NUM_LIT:10>])[<NUM_LIT:0>]<EOL>if compression_method == <NUM_LIT:0>:<EOL><INDENT>return raw_zip_data<EOL><DEDENT>dec = zlib.decompressobj(-zlib.MAX_WBITS)<EOL>for chunk in raw_zip_data:<EOL><INDENT>rv = dec.decompress(chunk)<EOL>if rv:<EOL><INDENT>uncompressed_data = uncompressed_data + rv<EOL><DEDENT><DEDENT>return uncompressed_data<EOL>
This function will extract a single file from the remote zip without downloading
the entire zip file. The filename argument should match whatever is in the 'filename'
key of the tableOfContents.