def writer_for_mimetype(stream, partition, url, params): if hasattr(params, 'mimetype'): cls = datasources.writers_by_mimetype[params.mimetype] return cls(stream) else: from disco.func import disco_output_stream return disco_output_stream(stream, partition, url, params)
def codec(self, compress_level = 0, version = 1, corrupt = False, ignore_corrupt = False): buf = cStringIO.StringIO() stream, url = disco_output_stream(buf, 0, "nourl", None, compress_level = compress_level, version = version) t = self.encode(stream, self.data) final_size = len(buf.getvalue()) final_mb = final_size / 1024**2 msg = "%1.2fMB encoded in %1.3fs (%1.2fMB/s), "\ "encoded size %1.3fMB (compress level: %d, version %d)" %\ (self.size, t, self.size / t, final_mb, compress_level, version) if corrupt: buf.seek(0) new = cStringIO.StringIO() new.write(buf.read(100)) new.write('X') buf.read(1) new.write(buf.read()) buf = new buf.seek(0) t, res = self.decode(buf, final_size, "nourl", ignore_corrupt = ignore_corrupt) if not ignore_corrupt: print "%s, decoded in %1.3fs (%1.2fMB/s)" % (msg, t, self.size / t) return res