def copyfile_and_gzip(self, source_path, target_path):
<EOL>target_dir = path.dirname(target_path)<EOL>if not self.fs.exists(target_dir):<EOL><INDENT>try:<EOL><INDENT>self.fs.makedirs(target_dir)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>guess = mimetypes.guess_type(source_path)<EOL>content_type = guess[<NUM_LIT:0>]<EOL>encoding = guess[<NUM_LIT:1>]<EOL>if content_type not in self.gzip_file_match:<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>"<STR_LIT>",<EOL>source_path,<EOL>self.fs_name,<EOL>target_path<EOL>))<EOL>copy.copy_file("<STR_LIT>", smart_text(source_path), self.fs, smart_text(target_path))<EOL><DEDENT>elif encoding == '<STR_LIT>':<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>"<STR_LIT>",<EOL>source_path,<EOL>self.fs_name,<EOL>target_path<EOL>))<EOL>copy.copy_file("<STR_LIT>", smart_text(source_path), self.fs, smart_text(target_path))<EOL><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>"<STR_LIT>",<EOL>source_path,<EOL>self.fs_name,<EOL>target_path<EOL>))<EOL>with open(source_path, '<STR_LIT:rb>') as source_file:<EOL><INDENT>data_buffer = six.BytesIO()<EOL>kwargs = dict(<EOL>filename=path.basename(target_path),<EOL>mode='<STR_LIT:wb>',<EOL>fileobj=data_buffer<EOL>)<EOL>if float(sys.version[:<NUM_LIT:3>]) >= <NUM_LIT>:<EOL><INDENT>kwargs['<STR_LIT>'] = <NUM_LIT:0><EOL><DEDENT>with gzip.GzipFile(**kwargs) as f:<EOL><INDENT>f.write(six.binary_type(source_file.read()))<EOL><DEDENT>with self.fs.open(smart_text(target_path), '<STR_LIT:wb>') as outfile:<EOL><INDENT>outfile.write(data_buffer.getvalue())<EOL>outfile.close()<EOL><DEDENT><DEDENT><DEDENT>
Copies the provided file to the provided target directory.

Gzips JavaScript, CSS and HTML and other files along the way.