python chunk模块
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
最新文章
- MVC中渲染页面
- SqlServer性能优化 即席查询(十三)
- 谁能完全搞懂Visual Studio的安装项?
- IE插件收集
- ACM2 递归 n分成k份
- ylbtech-LanguageSamples-Yield
- CSS属性值一览
- TCP并发server,每个客户一个子进程
- Delphi 记事本 TMemo
- Linux 压缩解压命令
- lucene-SpanNotQuery和SpanOrQuery交迭与全局跨度
- 不用分支语句实现1+2+。。。+n
- 用python代码模拟登录网站
- Django学习手册 - ORM 数据创建/表操作 汇总
- Angular2入门:TypeScript的类型 - 类型、null、undefined
- mybatis oracle -批量插入,存在则更新
- [Leetcode221]最大面积 Maximal Square
- HibernateDaoSupport类的使用(转)
- 如果datanode连接不上namenode,导致datanode无法启动。
- IOS设计模式第十篇之命令行设计模式
热门文章
- 【咸鱼教程】DragonBones帧动画、骨骼json、极速、二进制
- jenkins之-----------在必要的时候并发构建
- MAC SVN 基本设置 终端命令
- Spark版本发布历史,及其各版本特性
- Zabbix监控Nginx状态信息
- 处理 Java Tomcat 的“Cannot allocate memory”错误
- JNUOJ 1187 - 哨兵
- 使用代理*** and kubeadm init错误
- yum provides ";*/nmcli"; and apt-get
- python的几个注意事项