Skip to content

Commit

Permalink
get_buffers: always return same number of values
Browse files Browse the repository at this point in the history
Instead of returning two or three values depending on the arguments,
always return three values, with the third value being set to
bytes_to_read if known.

Updates every place that calls this method to ignore the third value if
it's not required/used.

Fixes #71.
  • Loading branch information
mistydemeo committed May 16, 2016
1 parent 1916c70 commit d3d5e23
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fido/fido.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def identify_file(self, filename):
self.current_filesize = size
if self.current_filesize == 0:
sys.stderr.write("FIDO: Zero byte file (empty): Path is: {0}\n".format(filename))
bofbuffer, eofbuffer = self.get_buffers(f, size, seekable=True)
bofbuffer, eofbuffer, _ = self.get_buffers(f, size, seekable=True)
matches = self.match_formats(bofbuffer, eofbuffer)
container_type = self.container_type(matches)
if container_type in ("zip", "ole"):
Expand Down Expand Up @@ -444,7 +444,7 @@ def identify_multi_object_stream(self, stream):
# Consume exactly content-length bytes
self.current_file = 'STDIN!(at ' + str(offset) + ' bytes)'
self.current_filesize = content_length
bofbuffer, eofbuffer = self.get_buffers(stream, content_length)
bofbuffer, eofbuffer, _ = self.get_buffers(stream, content_length)
matches = self.match_formats(bofbuffer, eofbuffer)
# MdR: this needs attention
if len(matches) > 0:
Expand Down Expand Up @@ -563,7 +563,7 @@ def get_buffers(self, stream, length=None, seekable=False):
self.blocking_read(stream, r)
# and read the remaining bufsize bytes into the eofbuffer
eofbuffer = self.blocking_read(stream, self.bufsize)
return bofbuffer, eofbuffer
return bofbuffer, eofbuffer, bytes_to_read

def walk_zip(self, filename, fileobj=None):
"""
Expand All @@ -584,7 +584,7 @@ def walk_zip(self, filename, fileobj=None):
self.current_filesize = item.file_size
if self.current_filesize == 0:
sys.stderr.write("FIDO: Zero byte file (empty): Path is: {0}\n".format(item_name))
bofbuffer, eofbuffer = self.get_buffers(f, item.file_size)
bofbuffer, eofbuffer, _ = self.get_buffers(f, item.file_size)
matches = self.match_formats(bofbuffer, eofbuffer)
if len(matches) > 0 and self.current_filesize > 0:
self.handle_matches(item_name, matches, time.clock() - t0, "signature")
Expand Down Expand Up @@ -619,7 +619,7 @@ def walk_tar(self, filename, fileobj):
tar_item_name = filename + '!' + item.name
self.current_file = tar_item_name
self.current_filesize = item.size
bofbuffer, eofbuffer = self.get_buffers(f, item.size)
bofbuffer, eofbuffer, _ = self.get_buffers(f, item.size)
matches = self.match_formats(bofbuffer, eofbuffer)
self.handle_matches(tar_item_name, matches, time.clock() - t0)
if self.container_type(matches):
Expand Down

0 comments on commit d3d5e23

Please sign in to comment.