From 6a627fc04e9b8cc500b83d2ae052afdc30ff8766 Mon Sep 17 00:00:00 2001 From: Hackintosh Date: Fri, 21 Jun 2019 08:32:47 +0100 Subject: [PATCH] Fix issue where attempting to download a binary file fails It occured because the file is opened in 'r' mode and .encode("utf-8")'d rather than just opening in 'rb' mode to start with. Sometimes a 'r' file may be provided, so we have to maintain compatibility with this case. --- adb/fastboot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adb/fastboot.py b/adb/fastboot.py index 1507494..1e08eba 100644 --- a/adb/fastboot.py +++ b/adb/fastboot.py @@ -312,13 +312,13 @@ def Download(self, source_file, source_len=0, """ if isinstance(source_file, str): source_len = os.stat(source_file).st_size - source_file = open(source_file) + source_file = open(source_file, "rb") with source_file: if source_len == 0: # Fall back to storing it all in memory :( data = source_file.read() - source_file = io.BytesIO(data.encode('utf8')) + source_file = io.BytesIO(data if isinstance(data, bytes) else data.encode("utf-8")) source_len = len(data) self._protocol.SendCommand(b'download', b'%08x' % source_len)