Commits

Anonymous committed 0173123

* core.stream & urwid: remove InputStream.address
* fat parser: implement File._getIStreamTags

  • Participants
  • Parent commits a77de77

Comments (0)

Files changed (3)

hachoir-core/hachoir_core/stream/input.py

         if None < size <= 0:
             raise ValueError("InputSubStream: offset is outside input stream")
         self.stream = stream
-        self.address = offset
         self._offset = offset
         if source is None:
             source = "<substream input=%s offset=%s size=%s>" % \
 class FragmentedStream(InputStream):
     def __init__(self, field, size=None):
         self.stream = field.parent.stream
-        self.address = field.absolute_address
         data = field.getData()
         self.fragments = [ (0, data.absolute_address, data.size) ]
         self.next = field.next
         if size is not None:
             size += self.__size0
         self.__streams = streams
-        self.address = None
         InputStream.__init__(self, source, size)
 
     _current_size = property(lambda self: self.__size0 + self.__streams[1]._current_size)

hachoir-parser/hachoir_parser/file_system/fat.py

 from hachoir_core.endian import LITTLE_ENDIAN
 from hachoir_core.text_handler import hexadecimal
 from hachoir_core.error import error
+from hachoir_core.tools import humanFilesize
 import datetime
 import re
 
 
 
 class InodeLink(Link):
-    def __init__(self, parent, name, target_size, cluster, target=None):
+    def __init__(self, parent, name, target=None):
         Link.__init__(self, parent, name)
-        self.cluster = cluster
         self.target = target
-        self.target_size = target_size
         self.first = None
 
     def _getTargetPath(self):
         return self.target
 
     def createValue(self):
-        field = InodeGen(self["/"], self.cluster, self._getTargetPath(), self.target_size)(self)
+        field = InodeGen(self["/"], self.parent, self._getTargetPath())(self)
         self._display = field.path
         return Link.createValue(self)
 
                         target_size = 0
                 elif not target_size:
                     return
-                yield InodeLink(self, "data", 8*target_size, self.getCluster)
+                self.target_size = 8 * target_size
+                yield InodeLink(self, "data")
         else:
             yield UInt8(self, "seq_no", "Sequence Number")
             yield String(self, "name[]", 10, "(5 UTF-16 characters)",
             yield createPaddingField(self, padding)
 
 class InodeGen:
-    def __init__(self, root, cluster, path, filesize):
+    def __init__(self, root, entry, path):
         self.root = root
-        self.cluster = root.clusters(cluster)
+        self.cluster = root.clusters(entry.getCluster)
         self.path = path
-        self.filesize = filesize
+        self.filesize = entry.target_size
         self.done = 0
+        self.tags = lambda: [ ("filename", entry.getFilename()) ]
 
     def __call__(self, prev):
         name = self.path + "[]"
                 error("(FAT) bad metadata for " + self.path)
                 return
             field = File(self.root, name, size=size, first=prev.first)
+            if prev.first is None:
+                field._getIStreamTags = self.tags
+                field._description = 'File size: %s' % humanFilesize(self.filesize//8)
             field.datasize = min(self.filesize - self.done, size)
             self.done += field.datasize
         else:
         self.cluster_size = boot["cluster_size"].value * self.sector_size * 8
         self.fat = self["fat[0]"]
         if "root_start" in boot:
-            yield InodeLink(self, "root", 0, lambda: boot["root_start"].value, "root")
+            self.target_size = 0
+            self.getCluster = lambda: boot["root_start"].value
+            yield InodeLink(self, "root", "root")
         else:
             yield Directory(self, "root[]", size=boot["max_root"].value * 32 * 8)
         self.data_start = self.current_size - 2 * self.cluster_size

hachoir-urwid/hachoir_urwid/urwid_ui.py

                     if not parser:
                         hachoir_log.error(_("No parser found for %s") % stream.source)
                     else:
-                        body.append(("%u/%s" % (body.active, stream.address),
+                        body.append(("%u/%s" % (body.active, e.field.absolute_address),
                             TreeBox(charset, Node(parser, None), preload_fields, options)))
                         resize = log.height
                 except NeedInput, e: