我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用zlib.Z_BEST_COMPRESSION。
def run(self): print("VEDIO client starts...") while True: try: self.sock.connect(self.ADDR) break except: time.sleep(3) continue print("VEDIO client connected...") while self.cap.isOpened(): ret, frame = self.cap.read() sframe = cv2.resize(frame, (0,0), fx=self.fx, fy=self.fx) data = pickle.dumps(sframe) zdata = zlib.compress(data, zlib.Z_BEST_COMPRESSION) try: self.sock.sendall(struct.pack("L", len(zdata)) + zdata) except: break for i in range(self.interval): self.cap.read()
def marshall_key(self, key): """ Marshalls a Crash key to be used in the database. @see: L{__init__} @type key: L{Crash} key. @param key: Key to convert. @rtype: str or buffer @return: Converted key. """ if key in self.__keys: return self.__keys[key] skey = pickle.dumps(key, protocol = 0) if self.compressKeys: skey = zlib.compress(skey, zlib.Z_BEST_COMPRESSION) if self.escapeKeys: skey = skey.encode('hex') if self.binaryKeys: skey = buffer(skey) self.__keys[key] = skey return skey
def create_entry(name, data): zlength = [] output = BytesIO() for i in range(0, len(data), BLOCK_SIZE): raw = data[i: i + BLOCK_SIZE] compressed = zlib.compress(raw, zlib.Z_BEST_COMPRESSION) if len(compressed) < len(raw): output.write(compressed) zlength.append(len(compressed)) else: output.write(raw) zlength.append(len(raw) % BLOCK_SIZE) return { 'md5': md5(name.encode()).digest() if name != '' else bytes(16), 'zlength': zlength, 'length': len(data), 'data': output.getvalue() }
def run(self): print ("VEDIO client starts...") while True: try: self.sock.connect(self.ADDR) break except: time.sleep(3) continue print ("video client <-> remote server success connected...") check = "F" check = self.sock.recv(1) if check.decode("utf-8") != "S": return print ("receive authend") #self.cap = cv2.VideoCapture(0) self.cap = cv2.VideoCapture("test.mp4") if self.showme: cv2.namedWindow('You', cv2.WINDOW_NORMAL) print ("remote VEDIO client connected...") while self.cap.isOpened(): ret, frame = self.cap.read() if self.showme: cv2.imshow('You', frame) if cv2.waitKey(1) & 0xFF == 27: self.showme = False cv2.destroyWindow('You') if self.level > 0: frame = cv2.resize(frame, (0,0), fx=self.fx, fy=self.fx) data = pickle.dumps(frame) zdata = zlib.compress(data, zlib.Z_BEST_COMPRESSION) try: self.sock.sendall(struct.pack("L", len(zdata)) + zdata) print("video send ", len(zdata)) except: break for i in range(self.interval): self.cap.read()
def run(self): while True: try: self.sock.connect(self.ADDR) break except: time.sleep(3) continue if self.showme: cv2.namedWindow('You', cv2.WINDOW_NORMAL) print("VEDIO client connected...") while self.cap.isOpened(): ret, frame = self.cap.read() if self.showme: cv2.imshow('You', frame) if cv2.waitKey(1) & 0xFF == 27: self.showme = False cv2.destroyWindow('You') sframe = cv2.resize(frame, (0,0), fx=self.fx, fy=self.fx) data = pickle.dumps(sframe) zdata = zlib.compress(data, zlib.Z_BEST_COMPRESSION) try: self.sock.sendall(struct.pack("L", len(zdata)) + zdata) except: break for i in range(self.interval): self.cap.read()
def encrypt_sng(data, key): header = Int32ul.build(74) + Int32ul.build(3) iv = bytes(16) payload = Int32ul.build(len(data)) payload += zlib.compress(data, zlib.Z_BEST_COMPRESSION) encrypted = aes_sng(key, iv).encrypt(pad(payload))[:len(payload)] return header + iv + encrypted + bytes(56)
def marshall_value(self, value, storeMemoryMap = False): """ Marshalls a Crash object to be used in the database. By default the C{memoryMap} member is B{NOT} stored here. @warning: Setting the C{storeMemoryMap} argument to C{True} can lead to a severe performance penalty! @type value: L{Crash} @param value: Object to convert. @type storeMemoryMap: bool @param storeMemoryMap: C{True} to store the memory map, C{False} otherwise. @rtype: str @return: Converted object. """ if hasattr(value, 'memoryMap'): crash = value memoryMap = crash.memoryMap try: crash.memoryMap = None if storeMemoryMap and memoryMap is not None: # convert the generator to a list crash.memoryMap = list(memoryMap) if self.optimizeValues: value = pickle.dumps(crash, protocol = HIGHEST_PROTOCOL) value = optimize(value) else: value = pickle.dumps(crash, protocol = 0) finally: crash.memoryMap = memoryMap del memoryMap del crash if self.compressValues: value = zlib.compress(value, zlib.Z_BEST_COMPRESSION) if self.escapeValues: value = value.encode('hex') if self.binaryValues: value = buffer(value) return value