chunk模块用于读取TIFF格式的文件,打开应该使用二进制模式

TIFF 标签图像文件格式

import chunk

import chunk 

f=open('E:\\test.tiff','rb') 

print(type(f)) 

html=chunk.Chunk(f) 

print(html.getname()) 

print(html.getsize())

help('chunk')

Help on module chunk:

NAME

chunk - Simple class to read IFF chunks.

DESCRIPTION

An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File

Format)) has the following structure:

+----------------+

| ID (4 bytes)   |

+----------------+

| size (4 bytes) |

+----------------+

| data           |

| ...            |

+----------------+

The ID is a 4-byte string which identifies the type of chunk.

The size field (a 32-bit value, encoded using big-endian byte order)

gives the size of the whole chunk, including the 8-byte header.

Usually an IFF-type file consists of one or more chunks.  The proposed

usage of the Chunk class defined here is to instantiate an instance at

the start of each chunk and read from the instance until it reaches

the end, after which a new instance can be instantiated.  At the end

of the file, creating a new instance will fail with an EOFError

exception.

Usage:

while True:

try:

chunk = Chunk(file)

except EOFError:

break

chunktype = chunk.getname()

while True:

data = chunk.read(nbytes)

if not data:

pass

# do something with data

The interface is file-like.  The implemented methods are:

read, close, seek, tell, isatty.

Extra methods are: skip() (called by close, skips to the end of the chunk),

getname() (returns the name (ID) of the chunk)

The __init__ method has one required argument, a file-like object

(including a chunk instance), and one optional argument, a flag which

specifies whether or not chunks are aligned on 2-byte boundaries.  The

default is 1, i.e. aligned.

CLASSES

builtins.object

Chunk

class Chunk(builtins.object)

|  Methods defined here:

|

|  __init__(self, file, align=True, bigendian=True, inclheader=False)

|      Initialize self.  See help(type(self)) for accurate signature.

|

|  close(self)

|

|  getname(self)

|      Return the name (ID) of the current chunk.

|

|  getsize(self)

|      Return the size of the current chunk.

|

|  isatty(self)

|

|  read(self, size=-1)

|      Read at most size bytes from the chunk.

|      If size is omitted or negative, read until the end

|      of the chunk.

|

|  seek(self, pos, whence=0)

|      Seek to specified position into the chunk.

|      Default position is 0 (start of chunk).

|      If the file is not seekable, this will result in an error.

|

|  skip(self)

|      Skip the rest of the chunk.

|      If you are not interested in the contents of the chunk,

|      this method should be called so that the file points to

|      the start of the next chunk.

|

|  tell(self)

|

|  ----------------------------------------------------------------------

|  Data descriptors defined here:

|

|  __dict__

|      dictionary for instance variables (if defined)

|

|  __weakref__

|      list of weak references to the object (if defined)

FILE

c:\python3.5\lib\chunk.py

 
 
摘自:
https://www.cnblogs.com/dengyg200891/p/4947685.html
 

最新文章

  1. MVC中渲染页面
  2. SqlServer性能优化 即席查询(十三)
  3. 谁能完全搞懂Visual Studio的安装项?
  4. IE插件收集
  5. ACM2 递归 n分成k份
  6. ylbtech-LanguageSamples-Yield
  7. CSS属性值一览
  8. TCP并发server,每个客户一个子进程
  9. Delphi 记事本 TMemo
  10. Linux 压缩解压命令
  11. lucene-SpanNotQuery和SpanOrQuery交迭与全局跨度
  12. 不用分支语句实现1+2+。。。+n
  13. 用python代码模拟登录网站
  14. Django学习手册 - ORM 数据创建/表操作 汇总
  15. Angular2入门:TypeScript的类型 - 类型、null、undefined
  16. mybatis oracle -批量插入,存在则更新
  17. [Leetcode221]最大面积 Maximal Square
  18. HibernateDaoSupport类的使用(转)
  19. 如果datanode连接不上namenode,导致datanode无法启动。
  20. IOS设计模式第十篇之命令行设计模式

热门文章

  1. 【咸鱼教程】DragonBones帧动画、骨骼json、极速、二进制
  2. jenkins之-----------在必要的时候并发构建
  3. MAC SVN 基本设置 终端命令
  4. Spark版本发布历史,及其各版本特性
  5. Zabbix监控Nginx状态信息
  6. 处理 Java Tomcat 的“Cannot allocate memory”错误
  7. JNUOJ 1187 - 哨兵
  8. 使用代理*** and kubeadm init错误
  9. yum provides "*/nmcli" and apt-get
  10. python的几个注意事项