60 | | sys.stderr.write("ZjStream is not supported yet, returning 0 pages.\n") |
61 | | return 0 |
| 62 | infileno = self.infile.fileno() |
| 63 | minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) |
| 64 | pos = 4 |
| 65 | startpagecount = endpagecount = 0 |
| 66 | try : |
| 67 | try : |
| 68 | while 1 : |
| 69 | header = minfile[pos:pos+16] |
| 70 | if len(header) != 16 : |
| 71 | break |
| 72 | totalChunkSize = unpack(self.unpackLong, header[:4])[0] |
| 73 | chunkType = unpack(self.unpackLong, header[4:8])[0] |
| 74 | numberOfItems = unpack(self.unpackLong, header[8:12])[0] |
| 75 | reserved = unpack(self.unpackShort, header[12:14])[0] |
| 76 | signature = unpack(self.unpackShort, header[14:])[0] |
| 77 | pos += totalChunkSize |
| 78 | if chunkType == 0 : |
| 79 | self.logdebug("startDoc") |
| 80 | elif chunkType == 1 : |
| 81 | self.logdebug("endDoc") |
| 82 | elif chunkType == 2 : |
| 83 | self.logdebug("startPage") |
| 84 | startpagecount += 1 |
| 85 | elif chunkType == 3 : |
| 86 | self.logdebug("endPage") |
| 87 | endpagecount += 1 |
| 88 | |
| 89 | #self.logdebug("Chunk size : %s" % totalChunkSize) |
| 90 | #self.logdebug("Chunk type : 0x%08x" % chunkType) |
| 91 | #self.logdebug("# items : %s" % numberOfItems) |
| 92 | #self.logdebug("reserved : 0x%04x" % reserved) |
| 93 | #self.logdebug("signature : 0x%04x" % signature) |
| 94 | #self.logdebug("\n") |
| 95 | except IndexError : # EOF ? |
| 96 | pass |
| 97 | finally : |
| 98 | minfile.close() |
| 99 | |
| 100 | if startpagecount != endpagecount : |
| 101 | sys.stderr.write("ERROR : Incorrect ZjStream datas.\n") |
| 102 | return max(startpagecount, endpagecount) |