def _read_zipfile(self, ftppath): zipf = BytesIO() try: self._sec_ftp_session.retrbinary('RETR ' + ftppath, zipf.write) except EOFError: raise RemoteDataError('FTP server has closed the connection.') zipf.seek(0) with ZipFile(zipf, 'r') as zf: data = zf.open(zf.namelist()[0]).read().decode() return StringIO(data)
def _read_gzfile(self, ftppath): zipf = BytesIO() try: self._sec_ftp_session.retrbinary('RETR ' + ftppath, zipf.write) except EOFError: raise RemoteDataError('FTP server has closed the connection.') zipf.seek(0) zf = gzip.GzipFile(fileobj=zipf, mode='rb') try: data = zf.read().decode('iso-8859-1') finally: zf.close() return StringIO(data)