summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-01-28 23:34:37 +0100
committernfnty <git@nfnty.se>2017-01-28 23:50:22 +0100
commit2a0af8e87cb9f2bda2857154f33ceee019bf3f9c (patch)
treead70def871ef98ba186a485d505005a9b3641fd8
parente9d8f70031690cf34a4fddb51e9c422260b553a8 (diff)
downloadranger-2a0af8e87cb9f2bda2857154f33ceee019bf3f9c.tar.gz
container.file: File.firstbytes: Handle `UnicodeDecodeError`
Fixes #784
-rw-r--r--ranger/container/file.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/ranger/container/file.py b/ranger/container/file.py
index e0b9922c..88097a2c 100644
--- a/ranger/container/file.py
+++ b/ranger/container/file.py
@@ -55,7 +55,10 @@ class File(FileSystemObject):
         if self._firstbytes is None:
             try:
                 with open(self.path, 'r') as fobj:
-                    self._firstbytes = fobj.read(N_FIRST_BYTES)
+                    try:
+                        self._firstbytes = fobj.read(N_FIRST_BYTES)
+                    except UnicodeDecodeError:
+                        return None
             except OSError:
                 return None
         return self._firstbytes