manual.ps
上传用户:zswatin
上传日期:2007-01-06
资源大小:440k
文件大小:457k
源码类别:

压缩解压

开发平台:

C/C++

  1. Fl(.)150 808 y(F)-8 b(or)36 b(general)e(bac)m(kground)h(information,)f
  2. (particularly)f(ab)s(out)h(memory)h(use)f(and)g(p)s(erformance)g(as-)
  3. 150 917 y(p)s(ects,)d(y)m(ou'd)f(b)s(e)g(w)m(ell)f(advised)g(to)j(read)
  4. e(Chapter)g(2)g(as)h(w)m(ell.)150 1218 y Fk(3.1)68 b(T)-11
  5. b(op-lev)l(el)46 b(structure)150 1411 y Fj(libbzip2)33
  6. b Fl(is)i(a)h(15exible)e(library)f(for)j(compressing)f(and)g
  7. (decompressing)f(data)j(in)d(the)i Fj(bzip2)e Fl(data)150
  8. 1520 y(format.)39 b(Although)24 b(pac)m(k)-5 b(aged)26
  9. b(as)e(a)h(single)e(en)m(tit)m(y)-8 b(,)27 b(it)d(helps)f(to)i(regard)g
  10. (the)g(library)d(as)i(three)h(separate)150 1630 y(parts:)40
  11. b(the)31 b(lo)m(w)f(lev)m(el)g(in)m(terface,)h(and)f(the)h(high)e(lev)m
  12. (el)h(in)m(terface,)h(and)f(some)h(utilit)m(y)d(functions.)150
  13. 1787 y(The)38 b(structure)g(of)g Fj(libbzip2)p Fl('s)e(in)m(terfaces)j
  14. (is)e(similar)f(to)j(that)g(of)g(Jean-loup)e(Gailly's)g(and)h(Mark)150
  15. 1896 y(Adler's)29 b(excellen)m(t)i Fj(zlib)e Fl(library)-8
  16. b(.)150 2157 y Ff(3.1.1)63 b(Lo)m(w-lev)m(el)39 b(summary)150
  17. 2349 y Fl(This)21 b(in)m(terface)h(pro)m(vides)g(services)g(for)g
  18. (compressing)f(and)h(decompressing)f(data)i(in)e(memory)-8
  19. b(.)38 b(There's)150 2459 y(no)43 b(pro)m(vision)e(for)h(dealing)g
  20. (with)f(14les,)k(streams)e(or)g(an)m(y)g(other)g(I/O)g(mec)m
  21. (hanisms,)i(just)e(straigh)m(t)150 2568 y(memory-to-memory)25
  22. b(w)m(ork.)38 b(In)23 b(fact,)k(this)22 b(part)i(of)f(the)h(library)d
  23. (can)j(b)s(e)f(compiled)f(without)h(inclusion)150 2678
  24. y(of)31 b Fj(stdio.h)p Fl(,)d(whic)m(h)h(ma)m(y)i(b)s(e)f(helpful)d
  25. (for)k(em)m(b)s(edded)e(applications.)150 2835 y(The)h(lo)m(w-lev)m(el)
  26. g(part)g(of)h(the)f(library)e(has)i(no)h(global)e(v)-5
  27. b(ariables)29 b(and)h(is)g(therefore)g(thread-safe.)150
  28. 2992 y(Six)f(routines)g(mak)m(e)j(up)d(the)i(lo)m(w)f(lev)m(el)g(in)m
  29. (terface:)41 b Fj(bzCompressInit)p Fl(,)27 b Fj(bzCompress)p
  30. Fl(,)h(and)150 3101 y Fj(bzCompressEnd)f Fl(for)j(compression,)g(and)f
  31. (a)i(corresp)s(onding)d(trio)i Fj(bzDecompressInit)p
  32. Fl(,)150 3211 y Fj(bzDecompress)41 b Fl(and)k Fj(bzDecompressEnd)40
  33. b Fl(for)45 b(decompression.)83 b(The)44 b Fj(*Init)f
  34. Fl(functions)g(allo)s(cate)150 3321 y(memory)31 b(for)g
  35. (compression/decompression)e(and)i(do)g(other)g(initialisations,)d
  36. (whilst)h(the)j Fj(*End)e Fl(func-)150 3430 y(tions)g(close)g(do)m(wn)g
  37. (op)s(erations)g(and)g(release)g(memory)-8 b(.)150 3587
  38. y(The)23 b(real)g(w)m(ork)h(is)f(done)g(b)m(y)g Fj(bzCompress)e
  39. Fl(and)i Fj(bzDecompress)p Fl(.)35 b(These)24 b(compress/decompress)f
  40. (data)150 3697 y(from)i(a)g(user-supplied)d(input)h(bu13er)h(to)i(a)g
  41. (user-supplied)c(output)i(bu13er.)38 b(These)25 b(bu13ers)f(can)i
  42. (b)s(e)f(an)m(y)150 3806 y(size;)35 b(arbitrary)d(quan)m(tities)g(of)i
  43. (data)f(are)h(handled)d(b)m(y)i(making)g(rep)s(eated)g(calls)g(to)g
  44. (these)h(functions.)150 3916 y(This)f(is)h(a)i(15exible)d(mec)m
  45. (hanism)i(allo)m(wing)f(a)h(consumer-pull)d(st)m(yle)k(of)f(activit)m
  46. (y)-8 b(,)37 b(or)f(pro)s(ducer-push,)150 4025 y(or)30
  47. b(a)h(mixture)e(of)i(b)s(oth.)150 4286 y Ff(3.1.2)63
  48. b(High-lev)m(el)41 b(summary)150 4478 y Fl(This)d(in)m(terface)j(pro)m
  49. (vides)e(some)h(handy)f(wrapp)s(ers)f(around)h(the)i(lo)m(w-lev)m(el)f
  50. (in)m(terface)g(to)h(facilitate)150 4588 y(reading)26
  51. b(and)g(writing)f Fj(bzip2)g Fl(format)i(14les)f(()p
  52. Fj(.bz2)g Fl(14les).)38 b(The)27 b(routines)e(pro)m(vide)h(ho)s(oks)
  53. h(to)g(facilitate)150 4698 y(reading)43 b(14les)f(in)h(whic)m(h)f
  54. (the)i Fj(bzip2)f Fl(data)h(stream)g(is)f(em)m(b)s(edded)f(within)g
  55. (some)i(larger-scale)g(14le)150 4807 y(structure,)30
  56. b(or)h(where)e(there)i(are)g(m)m(ultiple)d Fj(bzip2)h
  57. Fl(data)i(streams)f(concatenated)j(end-to-end.)150 4964
  58. y(F)-8 b(or)36 b(reading)e(14les,)i Fj(bzReadOpen)p
  59. Fl(,)e Fj(bzRead)p Fl(,)h Fj(bzReadClose)d Fl(and)i Fj(bzReadGetUnused)
  60. d Fl(are)36 b(supplied.)150 5074 y(F)-8 b(or)31 b(writing)e(14les,)g
  61. Fj(bzWriteOpen)p Fl(,)f Fj(bzWrite)g Fl(and)i Fj(bzWriteFinish)d
  62. Fl(are)j(a)m(v)-5 b(ailable.)150 5230 y(As)24 b(with)f(the)h(lo)m
  63. (w-lev)m(el)h(library)-8 b(,)23 b(no)h(global)g(v)-5
  64. b(ariables)23 b(are)h(used)g(so)g(the)h(library)c(is)j(p)s(er)f(se)h
  65. (thread-safe.)150 5340 y(Ho)m(w)m(ev)m(er,)32 b(if)c(I/O)h(errors)g(o)s
  66. (ccur)g(whilst)e(reading)i(or)g(writing)e(the)j(underlying)c
  67. (compressed)j(14les,)g(y)m(ou)p eop
  68. %%Page: 12 13
  69. 12 12 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  70. b(with)g Fj(libbzip2)1881 b Fl(12)150 366 y(ma)m(y)32
  71. b(ha)m(v)m(e)g(to)g(consult)e Fj(errno)g Fl(to)h(determine)g(the)g
  72. (cause)g(of)h(the)f(error.)42 b(In)30 b(that)i(case,)h(y)m(ou'd)e(need)
  73. g(a)150 476 y(C)f(library)e(whic)m(h)h(correctly)i(supp)s(orts)d
  74. Fj(errno)h Fl(in)g(a)i(m)m(ultithreaded)e(en)m(vironmen)m(t.)150
  75. 633 y(T)-8 b(o)44 b(mak)m(e)h(the)f(library)d(a)j(little)f(simpler)e
  76. (and)j(more)g(p)s(ortable,)i Fj(bzReadOpen)41 b Fl(and)i
  77. Fj(bzWriteOpen)150 742 y Fl(require)20 b(y)m(ou)h(to)h(pass)e(them)h
  78. (14le)f(handles)f(()p Fj(FILE*)p Fl(s))h(whic)m(h)g(ha)m(v)m(e)i
  79. (previously)d(b)s(een)h(op)s(ened)g(for)h(reading)150
  80. 852 y(or)j(writing)d(resp)s(ectiv)m(ely)-8 b(.)39 b(That)23
  81. b(a)m(v)m(oids)h(p)s(ortabilit)m(y)e(problems)g(asso)s(ciated)i(with)f
  82. (14le)g(op)s(erations)g(and)150 962 y(14le)29 b(attributes,)i
  83. (whilst)d(not)i(b)s(eing)f(m)m(uc)m(h)i(of)f(an)h(imp)s(osition)c(on)j
  84. (the)h(programmer.)150 1202 y Ff(3.1.3)63 b(Utilit)m(y)40
  85. b(functions)h(summary)150 1394 y Fl(F)-8 b(or)46 b(v)m(ery)g(simple)e
  86. (needs,)49 b Fj(bzBuffToBuffCompress)40 b Fl(and)45 b
  87. Fj(bzBuffToBuffDecompress)39 b Fl(are)46 b(pro-)150 1504
  88. y(vided.)37 b(These)23 b(compress)f(data)i(in)e(memory)h(from)f(one)i
  89. (bu13er)e(to)h(another)g(bu13er)f(in)g(a)i(single)d(function)150
  90. 1614 y(call.)60 b(Y)-8 b(ou)37 b(should)e(assess)j(whether)e(these)h
  91. (functions)f(ful14ll)d(y)m(our)k(memory-to-memory)i(compres-)150
  92. 1723 y(sion/decompression)28 b(requiremen)m(ts)g(b)s(efore)g(in)m(v)m
  93. (esting)h(e13ort)h(in)e(understanding)e(the)k(more)f(general)150
  94. 1833 y(but)h(more)g(complex)g(lo)m(w-lev)m(el)g(in)m(terface.)150
  95. 1990 y(Y)-8 b(oshiok)j(a)47 b(Tsuneo)e(()p Fj
  96. (QWF00133@niftyserve.or.jp)40 b Fl(/)46 b Fj(tsuneo-y@is.aist-nara.ac.)
  97. o(jp)p Fl())40 b(has)150 2099 y(con)m(tributed)30 b(some)h(functions)e
  98. (to)i(giv)m(e)g(b)s(etter)f Fj(zlib)g Fl(compatibilit)m(y)-8
  99. b(.)39 b(These)31 b(functions)e(are)h Fj(bzopen)p Fl(,)150
  100. 2209 y Fj(bzread)p Fl(,)43 b Fj(bzwrite)p Fl(,)f Fj(bzflush)p
  101. Fl(,)g Fj(bzclose)p Fl(,)g Fj(bzerror)e Fl(and)g Fj(bzlibVersion)p
  102. Fl(.)70 b(Y)-8 b(ou)42 b(ma)m(y)g(14nd)d(these)150
  103. 2318 y(functions)31 b(more)i(con)m(v)m(enien)m(t)h(for)f(simple)d
  104. (14le)i(reading)g(and)g(writing,)g(than)h(those)g(in)e(the)i
  105. (high-lev)m(el)150 2428 y(in)m(terface.)61 b(These)37
  106. b(functions)e(are)j(not)f((y)m(et))i(o16cially)c(part)i(of)g(the)g
  107. (library)-8 b(,)37 b(and)g(are)g(not)g(further)150 2538
  108. y(do)s(cumen)m(ted)32 b(here.)48 b(If)33 b(they)f(break,)i(y)m(ou)f
  109. (get)h(to)g(k)m(eep)f(all)f(the)h(pieces.)47 b(I)33 b(hop)s(e)f(to)h
  110. (do)s(cumen)m(t)g(them)150 2647 y(prop)s(erly)28 b(when)i(time)g(p)s
  111. (ermits.)150 2804 y(Y)-8 b(oshiok)j(a)27 b(also)g(con)m(tributed)f(mo)s
  112. (di14cations)f(to)i(allo)m(w)f(the)h(library)e(to)i(b)s(e)f(built)f
  113. (as)i(a)g(Windo)m(ws)f(DLL.)150 3077 y Fk(3.2)68 b(Error)45
  114. b(handling)150 3270 y Fl(The)23 b(library)f(is)h(designed)g(to)i(reco)m
  115. (v)m(er)g(cleanly)f(in)e(all)h(situations,)h(including)d(the)j(w)m
  116. (orst-case)i(situation)150 3380 y(of)j(decompressing)e(random)g(data.)
  117. 41 b(I'm)28 b(not)h(10045)g(sure)f(that)h(it)f(can)h(alw)m(a)m(ys)g
  118. (do)f(this,)g(so)g(y)m(ou)h(migh)m(t)150 3489 y(w)m(an)m(t)i(to)g(add)e
  119. (a)i(signal)d(handler)g(to)j(catc)m(h)h(segmen)m(tation)f(violations)e
  120. (during)f(decompression)h(if)g(y)m(ou)150 3599 y(are)g(feeling)f(esp)s
  121. (ecially)f(paranoid.)39 b(I)28 b(w)m(ould)g(b)s(e)g(in)m(terested)h(in)
  122. e(hearing)h(more)h(ab)s(out)f(the)h(robustness)150 3708
  123. y(of)i(the)f(library)e(to)j(corrupted)f(compressed)g(data.)150
  124. 3865 y(The)25 b(14le)g Fj(bzlib.h)f Fl(con)m(tains)i(all)f
  125. (de14nitions)e(needed)i(to)i(use)e(the)h(library)-8
  126. b(.)37 b(In)26 b(particular,)f(y)m(ou)h(should)150 3975
  127. y(de14nitely)i(not)j(include)d Fj(bzlib_private.h)p
  128. Fl(.)150 4132 y(In)39 b Fj(bzlib.h)p Fl(,)h(the)g(v)-5
  129. b(arious)39 b(return)f(v)-5 b(alues)39 b(are)h(de14ned.)68
  130. b(The)39 b(follo)m(wing)f(list)h(is)f(not)i(in)m(tended)f(as)150
  131. 4241 y(an)c(exhaustiv)m(e)h(description)d(of)i(the)h(circumstances)f
  132. (in)f(whic)m(h)g(a)i(giv)m(en)f(v)-5 b(alue)35 b(ma)m(y)h(b)s(e)e
  133. (returned)h({)150 4351 y(those)h(descriptions)d(are)j(giv)m(en)f
  134. (later.)56 b(Rather,)37 b(it)d(is)h(in)m(tended)f(to)i(con)m(v)m(ey)h
  135. (the)e(rough)g(meaning)g(of)150 4460 y(eac)m(h)j(return)d(v)-5
  136. b(alue.)59 b(The)36 b(14rst)g(14v)m(e)g(actions)h(are)g(normal)f
  137. (and)f(not)i(in)m(tended)f(to)h(denote)g(an)f(error)150
  138. 4570 y(situation.)150 4749 y Fj(BZ_OK)240 b Fl(The)30
  139. b(requested)g(action)h(w)m(as)g(completed)f(successfully)-8
  140. b(.)150 4902 y Fj(BZ_RUN_OK)150 5011 y(BZ_FLUSH_OK)150
  141. 5121 y(BZ_FINISH_OK)630 5230 y Fl(In)21 b Fj(bzCompress)p
  142. Fl(,)f(the)h(requested)h(15ush/14nish/nothing-sp)s(ecial)16
  143. b(action)21 b(w)m(as)h(completed)630 5340 y(successfully)-8
  144. b(.)p eop
  145. %%Page: 13 14
  146. 13 13 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  147. b(with)g Fj(libbzip2)1881 b Fl(13)150 366 y Fj(BZ_STREAM_END)630
  148. 476 y Fl(Compression)38 b(of)j(data)f(w)m(as)h(completed,)h(or)f(the)f
  149. (logical)f(stream)i(end)e(w)m(as)i(detected)630 586 y(during)28
  150. b(decompression.)150 760 y(The)i(follo)m(wing)f(return)g(v)-5
  151. b(alues)30 b(indicate)f(an)h(error)g(of)h(some)g(kind.)150
  152. 934 y Fj(BZ_SEQUENCE_ERROR)630 1043 y Fl(When)43 b(using)f(the)i
  153. (library)-8 b(,)45 b(it)e(is)f(imp)s(ortan)m(t)h(to)h(call)e(the)i
  154. (functions)e(in)g(the)i(correct)630 1153 y(sequence)28
  155. b(and)f(with)f(data)j(structures)e((bu13ers)f(etc))j(in)e(the)g
  156. (correct)i(states.)41 b Fj(libbzip2)630 1263 y Fl(c)m(hec)m(ks)26
  157. b(as)e(m)m(uc)m(h)h(as)f(it)g(can)g(to)h(ensure)f(this)f(is)g(happ)s
  158. (ening,)h(and)f(returns)g Fj(BZ_SEQUENCE_)630 1372 y(ERROR)36
  159. b Fl(if)h(not.)62 b(Co)s(de)37 b(whic)m(h)g(complies)f(precisely)g
  160. (with)h(the)g(function)g(seman)m(tics,)j(as)630 1482
  161. y(detailed)d(b)s(elo)m(w,)i(should)d(nev)m(er)i(receiv)m(e)h(this)d(v)
  162. -5 b(alue;)41 b(suc)m(h)d(an)g(ev)m(en)m(t)h(denotes)f(buggy)630
  163. 1591 y(co)s(de)31 b(whic)m(h)e(y)m(ou)h(should)f(in)m(v)m(estigate.)150
  164. 1736 y Fj(BZ_PARAM_ERROR)630 1845 y Fl(Returned)43 b(when)f(a)i
  165. (parameter)g(to)h(a)f(function)e(call)h(is)f(out)i(of)g(range)g(or)g
  166. (otherwise)630 1955 y(manifestly)34 b(incorrect.)57 b(As)36
  167. b(with)e Fj(BZ_SEQUENCE_ERROR)p Fl(,)f(this)i(denotes)h(a)g(bug)f(in)g
  168. (the)630 2064 y(clien)m(t)23 b(co)s(de.)39 b(The)22 b(distinction)f(b)s
  169. (et)m(w)m(een)j Fj(BZ_PARAM_ERROR)c Fl(and)j Fj(BZ_SEQUENCE_ERROR)630
  170. 2174 y Fl(is)29 b(a)i(bit)f(hazy)-8 b(,)31 b(but)f(still)e(w)m(orth)i
  171. (making.)150 2318 y Fj(BZ_MEM_ERROR)630 2428 y Fl(Returned)g(when)f(a)i
  172. (request)f(to)i(allo)s(cate)f(memory)f(failed.)40 b(Note)31
  173. b(that)g(the)g(quan)m(tit)m(y)g(of)630 2537 y(memory)21
  174. b(needed)g(to)i(decompress)e(a)g(stream)h(cannot)g(b)s(e)f(determined)f
  175. (un)m(til)g(the)h(stream's)630 2647 y(header)j(has)g(b)s(een)f(read.)39
  176. b(So)24 b Fj(bzDecompress)d Fl(and)i Fj(bzRead)g Fl(ma)m(y)h(return)f
  177. Fj(BZ_MEM_ERROR)630 2756 y Fl(ev)m(en)43 b(though)f(some)g(of)h(the)f
  178. (compressed)g(data)h(has)f(b)s(een)f(read.)76 b(The)42
  179. b(same)g(is)g(not)630 2866 y(true)32 b(for)g(compression;)g(once)h
  180. Fj(bzCompressInit)28 b Fl(or)k Fj(bzWriteOpen)d Fl(ha)m(v)m(e)k
  181. (successfully)630 2976 y(completed,)e Fj(BZ_MEM_ERROR)c
  182. Fl(cannot)k(o)s(ccur.)150 3120 y Fj(BZ_DATA_ERROR)630
  183. 3229 y Fl(Returned)h(when)g(a)h(data)g(in)m(tegrit)m(y)g(error)g(is)e
  184. (detected)k(during)30 b(decompression.)47 b(Most)630
  185. 3339 y(imp)s(ortan)m(tly)-8 b(,)31 b(this)f(means)i(when)f(stored)g
  186. (and)g(computed)h(CR)m(Cs)f(for)g(the)h(data)g(do)g(not)630
  187. 3448 y(matc)m(h.)41 b(This)28 b(v)-5 b(alue)29 b(is)f(also)i(returned)e
  188. (up)s(on)g(detection)i(of)g(an)m(y)g(other)f(anomaly)h(in)e(the)630
  189. 3558 y(compressed)i(data.)150 3702 y Fj(BZ_DATA_ERROR_MAGIC)630
  190. 3812 y Fl(As)k(a)g(sp)s(ecial)f(case)i(of)f Fj(BZ_DATA_ERROR)p
  191. Fl(,)d(it)i(is)g(sometimes)h(useful)e(to)j(kno)m(w)f(when)f(the)630
  192. 3921 y(compressed)d(stream)h(do)s(es)f(not)g(start)h(with)e(the)i
  193. (correct)h(magic)e(b)m(ytes)h(()p Fj('B')f('Z')f('h')p
  194. Fl().)150 4065 y Fj(BZ_IO_ERROR)630 4175 y Fl(Returned)42
  195. b(b)m(y)i Fj(bzRead)d Fl(and)i Fj(bzRead)e Fl(when)i(there)g(is)f(an)h
  196. (error)g(reading)g(or)g(writing)630 4285 y(in)34 b(the)i(compressed)f
  197. (14le,)h(and)f(b)m(y)g Fj(bzReadOpen)e Fl(and)i Fj(bzWriteOpen)d
  198. Fl(for)k(attempts)g(to)630 4394 y(use)43 b(a)g(14le)f(for)g(whic)m(h)
  199. g(the)h(error)f(indicator)g((viz,)k Fj(ferror(f))p
  200. Fl())41 b(is)g(set.)79 b(On)42 b(receipt)630 4504 y(of)j
  201. Fj(BZ_IO_ERROR)p Fl(,)h(the)f(caller)f(should)f(consult)h
  202. Fj(errno)g Fl(and/or)h Fj(perror)e Fl(to)i(acquire)630
  203. 4613 y(op)s(erating-system)30 b(sp)s(eci14c)f(information)g(ab)s(out)
  204. h(the)h(problem.)150 4758 y Fj(BZ_UNEXPECTED_EOF)630
  205. 4867 y Fl(Returned)d(b)m(y)g Fj(bzRead)f Fl(when)h(the)g(compressed)h
  206. (14le)e(14nishes)g(b)s(efore)h(the)h(logical)f(end)g(of)630
  207. 4977 y(stream)j(is)e(detected.)150 5121 y Fj(BZ_OUTBUFF_FULL)630
  208. 5230 y Fl(Returned)39 b(b)m(y)h Fj(bzBuffToBuffCompress)35
  209. b Fl(and)k Fj(bzBuffToBuffDecompress)34 b Fl(to)41 b(indi-)630
  210. 5340 y(cate)32 b(that)f(the)f(output)g(data)i(will)27
  211. b(not)k(14t)f(in)m(to)g(the)h(output)f(bu13er)f(pro)m(vided.)p
  212. eop
  213. %%Page: 14 15
  214. 14 14 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  215. b(with)g Fj(libbzip2)1881 b Fl(14)150 366 y Fk(3.3)68
  216. b(Lo)l(w-lev)l(el)47 b(in)l(terface)150 661 y Ff(3.3.1)63
  217. b Fe(bzCompressInit)390 848 y Fj(typedef)533 952 y(struct)46
  218. b({)676 1056 y(char)h(*next_in;)676 1159 y(unsigned)f(int)h(avail_in;)
  219. 676 1263 y(unsigned)f(int)h(total_in;)676 1471 y(char)g(*next_out;)676
  220. 1575 y(unsigned)f(int)h(avail_out;)676 1678 y(unsigned)f(int)h
  221. (total_out;)676 1886 y(void)g(*state;)676 2093 y(void)g
  222. (*(*bzalloc)(void)c(*,int,int);)676 2197 y(void)k
  223. ((*bzfree)(void)d(*,void)i(*);)676 2301 y(void)h(*opaque;)533
  224. 2405 y(})533 2509 y(bz_stream;)390 2716 y(int)g(bzCompressInit)d(()j
  225. (bz_stream)f(*strm,)1392 2820 y(int)h(blockSize100k,)1392
  226. 2924 y(int)g(verbosity,)1392 3027 y(int)g(workFactor)e();)150
  227. 3288 y Fl(Prepares)32 b(for)h(compression.)47 b(The)32
  228. b Fj(bz_stream)e Fl(structure)j(holds)e(all)h(data)h(p)s(ertaining)e
  229. (to)i(the)g(com-)150 3398 y(pression)i(activit)m(y)-8
  230. b(.)62 b(A)37 b Fj(bz_stream)e Fl(structure)h(should)f(b)s(e)i(allo)s
  231. (cated)g(and)f(initialised)e(prior)h(to)j(the)150 3507
  232. y(call.)67 b(The)39 b(14elds)e(of)j Fj(bz_stream)d
  233. Fl(comprise)h(the)i(en)m(tiret)m(y)g(of)f(the)h(user-visible)c(data.)68
  234. b Fj(state)38 b Fl(is)h(a)150 3617 y(p)s(oin)m(ter)29
  235. b(to)i(the)g(priv)-5 b(ate)30 b(data)h(structures)f(required)e(for)i
  236. (compression.)150 3774 y(Custom)37 b(memory)g(allo)s(cators)g(are)h
  237. (supp)s(orted,)f(via)g(14elds)f Fj(bzalloc)p Fl(,)h
  238. Fj(bzfree)p Fl(,)g(and)g Fj(opaque)p Fl(.)59 b(The)150
  239. 3883 y(v)-5 b(alue)32 b Fj(opaque)e Fl(is)i(passed)f(to)i(as)g(the)f
  240. (14rst)g(argumen)m(t)h(to)g(all)e(calls)g(to)i Fj(bzalloc)d
  241. Fl(and)i Fj(bzfree)p Fl(,)f(but)h(is)150 3993 y(otherwise)d(ignored)g
  242. (b)m(y)h(the)g(library)-8 b(.)38 b(The)29 b(call)h Fj(bzalloc)e(()i
  243. (opaque,)e(n,)i(m)g())g Fl(is)e(exp)s(ected)j(to)f(return)150
  244. 4102 y(a)g(p)s(oin)m(ter)e Fj(p)h Fl(to)h Fj(n)g(*)g(m)f
  245. Fl(b)m(ytes)h(of)g(memory)-8 b(,)30 b(and)e Fj(bzfree)h(()h(opaque,)f
  246. (p)h())f Fl(should)e(free)i(that)h(memory)-8 b(.)150
  247. 4259 y(If)33 b(y)m(ou)g(don't)h(w)m(an)m(t)g(to)g(use)f(a)g(custom)h
  248. (memory)f(allo)s(cator,)h(set)g Fj(bzalloc)p Fl(,)e Fj(bzfree)g
  249. Fl(and)h Fj(opaque)e Fl(to)150 4369 y Fj(NULL)p Fl(,)e(and)h(the)h
  250. (library)d(will)f(then)k(use)f(the)g(standard)g Fj(malloc)p
  251. Fl(/)p Fj(free)e Fl(routines.)150 4526 y(Before)h(calling)e
  252. Fj(bzCompressInit)p Fl(,)e(14elds)i Fj(bzalloc)p Fl(,)g
  253. Fj(bzfree)g Fl(and)h Fj(opaque)f Fl(should)f(b)s(e)i(14lled)e(appro-)
  254. 150 4635 y(priately)-8 b(,)40 b(as)e(just)g(describ)s(ed.)62
  255. b(Up)s(on)37 b(return,)j(the)e(in)m(ternal)f(state)j(will)35
  256. b(ha)m(v)m(e)40 b(b)s(een)d(allo)s(cated)i(and)150 4745
  257. y(initialised,)31 b(and)h Fj(total_in)f Fl(and)i Fj(total_out)e
  258. Fl(will)g(ha)m(v)m(e)j(b)s(een)f(set)h(to)g(zero.)50
  259. b(These)34 b(last)f(t)m(w)m(o)h(14elds)150 4854 y(are)29
  260. b(used)e(b)m(y)h(the)g(library)e(to)j(inform)e(the)h(caller)g(of)g(the)
  261. g(total)h(amoun)m(t)g(of)f(data)h(passed)f(in)m(to)g(and)g(out)150
  262. 4964 y(of)j(the)f(library)-8 b(,)29 b(resp)s(ectiv)m(ely)-8
  263. b(.)40 b(Y)-8 b(ou)31 b(should)d(not)j(try)f(to)h(c)m(hange)h(them.)150
  264. 5121 y(P)m(arameter)e Fj(blockSize100k)25 b Fl(sp)s(eci14es)i(the)h
  265. (blo)s(c)m(k)g(size)h(to)g(b)s(e)f(used)f(for)h(compression.)40
  266. b(It)28 b(should)f(b)s(e)150 5230 y(a)k(v)-5 b(alue)30
  267. b(b)s(et)m(w)m(een)i(1)f(and)f(9)h(inclusiv)m(e,)e(and)h(the)h(actual)g
  268. (blo)s(c)m(k)f(size)g(used)g(is)g(100000)j(x)e(this)e(14gure.)42
  269. b(9)150 5340 y(giv)m(es)31 b(the)f(b)s(est)g(compression)g(but)f(tak)m
  270. (es)j(most)f(memory)-8 b(.)p eop
  271. %%Page: 15 16
  272. 15 15 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  273. b(with)g Fj(libbzip2)1881 b Fl(15)150 366 y(P)m(arameter)29
  274. b Fj(verbosity)c Fl(should)h(b)s(e)h(set)i(to)f(a)h(n)m(um)m(b)s(er)d
  275. (b)s(et)m(w)m(een)j(0)f(and)f(4)h(inclusiv)m(e.)38 b(0)28
  276. b(is)f(silen)m(t,)h(and)150 476 y(greater)j(n)m(um)m(b)s(ers)c(giv)m(e)
  277. j(increasingly)d(v)m(erb)s(ose)j(monitoring/debugging)d(output.)40
  278. b(If)29 b(the)g(library)e(has)150 586 y(b)s(een)j(compiled)e(with)i
  279. Fj(-DBZ_NO_STDIO)p Fl(,)d(no)j(suc)m(h)g(output)g(will)e(app)s(ear)h
  280. (for)h(an)m(y)h(v)m(erb)s(osit)m(y)f(setting.)150 742
  281. y(P)m(arameter)35 b Fj(workFactor)d Fl(con)m(trols)i(ho)m(w)g(the)g
  282. (compression)f(phase)h(b)s(eha)m(v)m(es)g(when)f(presen)m(ted)h(with)
  283. 150 852 y(w)m(orst)40 b(case,)j(highly)37 b(rep)s(etitiv)m(e,)k(input)d
  284. (data.)68 b(If)39 b(compression)g(runs)e(in)m(to)j(di16culties)d
  285. (caused)i(b)m(y)150 962 y(rep)s(etitiv)m(e)22 b(data,)j(some)e
  286. (pseudo-random)f(v)-5 b(ariations)22 b(are)h(inserted)e(in)m(to)i(the)g
  287. (blo)s(c)m(k,)h(and)e(compression)150 1071 y(is)29 b(restarted.)42
  288. b(Lo)m(w)m(er)31 b(v)-5 b(alues)30 b(of)h Fj(workFactor)c
  289. Fl(reduce)j(the)h(tolerance)g(of)g(compression)e(to)i(rep)s(etitiv)m(e)
  290. 150 1181 y(data.)50 b(Y)-8 b(ou)33 b(should)f(set)h(this)f(parameter)i
  291. (carefully;)f(to)s(o)h(lo)m(w,)g(and)f(compression)f(ratio)h
  292. (su13ers,)g(to)s(o)150 1290 y(high,)25 b(and)g(y)m(our)h(a)m(v)m
  293. (erage-to-w)m(orst)k(case)d(compression)d(times)i(can)f(b)s(ecome)h(v)m
  294. (ery)g(large.)40 b(The)25 b(default)150 1400 y(v)-5 b(alue)30
  295. b(of)g(30)i(giv)m(es)e(reasonable)h(b)s(eha)m(viour)d(o)m(v)m(er)k(a)f
  296. (wide)e(range)i(of)f(circumstances.)150 1557 y(Allo)m(w)m(able)h(v)-5
  297. b(alues)31 b(range)i(from)e(0)i(to)f(250)h(inclusiv)m(e.)44
  298. b(0)32 b(is)f(a)h(sp)s(ecial)f(case,)i(equiv)-5 b(alen)m(t)32
  299. b(to)g(using)f(the)150 1666 y(default)f(v)-5 b(alue)29
  300. b(of)i(30.)150 1823 y(Note)j(that)g(the)f(randomisation)e(pro)s(cess)i
  301. (is)f(en)m(tirely)g(transparen)m(t.)49 b(If)32 b(the)i(library)c
  302. (decides)i(to)i(ran-)150 1933 y(domise)43 b(and)g(restart)h
  303. (compression)e(on)i(a)g(blo)s(c)m(k,)i(it)d(do)s(es)h(so)f(without)g
  304. (commen)m(t.)81 b(Randomised)150 2042 y(blo)s(c)m(ks)38
  305. b(are)i(automatically)e(de-randomised)g(during)f(decompression,)j(so)f
  306. (data)h(in)m(tegrit)m(y)f(is)f(nev)m(er)150 2152 y(compromised.)150
  307. 2309 y(P)m(ossible)29 b(return)h(v)-5 b(alues:)572 2460
  308. y Fj(BZ_PARAM_ERROR)663 2564 y Fl(if)29 b Fj(strm)g Fl(is)h
  309. Fj(NULL)663 2667 y Fl(or)g Fj(blockSize)e(<)i Fl(1)h(or)f
  310. Fj(blockSize)e(>)i Fl(9)663 2771 y(or)g Fj(verbosity)e(<)i
  311. Fl(0)h(or)f Fj(verbosity)e(>)i Fl(4)663 2875 y(or)g Fj(workFactor)e(<)i
  312. Fl(0)g(or)h Fj(workFactor)c(>)j Fl(250)572 2979 y Fj(BZ_MEM_ERROR)663
  313. 3083 y Fl(if)f(not)i(enough)f(memory)g(is)f(a)m(v)-5
  314. b(ailable)572 3186 y Fj(BZ_OK)663 3290 y Fl(otherwise)150
  315. 3447 y(Allo)m(w)m(able)30 b(next)g(actions:)572 3598
  316. y Fj(bzCompress)663 3702 y Fl(if)f Fj(BZ_OK)g Fl(is)g(returned)572
  317. 3806 y(no)h(sp)s(eci14c)f(action)i(needed)f(in)f(case)i(of)g(error)
  318. 150 4135 y Ff(3.3.2)63 b Fe(bzCompress)533 4322 y Fj(int)47
  319. b(bzCompress)e(()j(bz_stream)d(*strm,)h(int)h(action)f();)150
  320. 4478 y Fl(Pro)m(vides)28 b(more)g(input)f(and/or)h(output)g(bu13er)g
  321. (space)h(for)f(the)h(library)-8 b(.)38 b(The)28 b(caller)g(main)m
  322. (tains)f(input)150 4588 y(and)j(output)g(bu13ers,)f(and)h(calls)g
  323. Fj(bzCompress)d Fl(to)k(transfer)f(data)h(b)s(et)m(w)m(een)g(them.)150
  324. 4745 y(Before)k(eac)m(h)g(call)d(to)j Fj(bzCompress)p
  325. Fl(,)d Fj(next_in)g Fl(should)f(p)s(oin)m(t)i(at)h(the)g(data)h(to)f(b)
  326. s(e)f(compressed,)i(and)150 4854 y Fj(avail_in)42 b Fl(should)g
  327. (indicate)g(ho)m(w)i(man)m(y)g(b)m(ytes)h(the)f(library)d(ma)m(y)k
  328. (read.)81 b Fj(bzCompress)41 b Fl(up)s(dates)150 4964
  329. y Fj(next_in)p Fl(,)29 b Fj(avail_in)f Fl(and)i Fj(total_in)e
  330. Fl(to)j(re15ect)g(the)f(n)m(um)m(b)s(er)f(of)i(b)m(ytes)g(it)f(has)g
  331. (read.)150 5121 y(Similarly)-8 b(,)27 b Fj(next_out)h
  332. Fl(should)g(p)s(oin)m(t)h(to)i(a)f(bu13er)f(in)g(whic)m(h)g(the)h
  333. (compressed)g(data)h(is)e(to)i(b)s(e)e(placed,)150 5230
  334. y(with)24 b Fj(avail_out)f Fl(indicating)g(ho)m(w)i(m)m(uc)m(h)h
  335. (output)f(space)h(is)e(a)m(v)-5 b(ailable.)38 b Fj(bzCompress)23
  336. b Fl(up)s(dates)h Fj(next_)150 5340 y(out)p Fl(,)30 b
  337. Fj(avail_out)e Fl(and)h Fj(total_out)f Fl(to)j(re15ect)g(the)g(n)m
  338. (um)m(b)s(er)e(of)h(b)m(ytes)h(output.)p eop
  339. %%Page: 16 17
  340. 16 16 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  341. b(with)g Fj(libbzip2)1881 b Fl(16)150 366 y(Y)-8 b(ou)23
  342. b(ma)m(y)f(pro)m(vide)f(and)h(remo)m(v)m(e)h(as)g(little)e(or)h(as)g(m)
  343. m(uc)m(h)g(data)h(as)f(y)m(ou)g(lik)m(e)g(on)g(eac)m(h)h(call)e(of)h
  344. Fj(bzCompress)p Fl(.)150 476 y(In)33 b(the)g(limit,)f(it)h(is)f
  345. (acceptable)i(to)g(supply)d(and)i(remo)m(v)m(e)h(data)g(one)g(b)m(yte)g
  346. (at)g(a)f(time,)h(although)f(this)150 586 y(w)m(ould)k(b)s(e)h
  347. (terribly)e(ine16cien)m(t.)64 b(Y)-8 b(ou)39 b(should)d(alw)m(a)m(ys)
  348. j(ensure)f(that)h(at)g(least)f(one)h(b)m(yte)g(of)f(output)150
  349. 695 y(space)31 b(is)e(a)m(v)-5 b(ailable)30 b(at)h(eac)m(h)h(call.)150
  350. 852 y(A)d(second)g(purp)s(ose)e(of)i Fj(bzCompress)d
  351. Fl(is)i(to)h(request)g(a)g(c)m(hange)h(of)f(mo)s(de)g(of)g(the)g
  352. (compressed)f(stream.)150 1009 y(Conceptually)-8 b(,)56
  353. b(a)c(compressed)f(stream)h(can)g(b)s(e)f(in)f(one)i(of)g(four)f
  354. (states:)84 b(IDLE,)51 b(R)m(UNNING,)150 1119 y(FLUSHING)39
  355. b(and)f(FINISHING.)i(Before)g(initialisation)35 b(()p
  356. Fj(bzCompressInit)p Fl())h(and)i(after)h(termina-)150
  357. 1228 y(tion)30 b(()p Fj(bzCompressEnd)p Fl(),)e(a)i(stream)h(is)e
  358. (regarded)i(as)f(IDLE.)150 1385 y(Up)s(on)i(initialisation)d(()p
  359. Fj(bzCompressInit)p Fl(),)h(the)i(stream)h(is)f(placed)g(in)f(the)i(R)
  360. m(UNNING)h(state.)48 b(Sub-)150 1495 y(sequen)m(t)31
  361. b(calls)f(to)i Fj(bzCompress)c Fl(should)h(pass)h Fj(BZ_RUN)f
  362. Fl(as)i(the)g(requested)g(action;)g(other)h(actions)f(are)150
  363. 1604 y(illegal)e(and)g(will)f(result)h(in)g Fj(BZ_SEQUENCE_ERROR)p
  364. Fl(.)150 1761 y(A)m(t)38 b(some)f(p)s(oin)m(t,)h(the)f(calling)e
  365. (program)i(will)d(ha)m(v)m(e)k(pro)m(vided)e(all)f(the)i(input)e(data)j
  366. (it)e(w)m(an)m(ts)i(to.)61 b(It)150 1871 y(will)28 b(then)h(w)m(an)m(t)
  367. i(to)g(14nish)d(up)h({)i(in)d(e13ect,)k(asking)e(the)g(library)e
  368. (to)j(pro)s(cess)f(an)m(y)g(data)h(it)f(migh)m(t)g(ha)m(v)m(e)150
  369. 1980 y(bu13ered)38 b(in)m(ternally)-8 b(.)67 b(In)39
  370. b(this)g(state,)k Fj(bzCompress)37 b Fl(will)g(no)i(longer)h(attempt)g
  371. (to)h(read)e(data)h(from)150 2090 y Fj(next_in)p Fl(,)33
  372. b(but)g(it)h(will)d(w)m(an)m(t)k(to)g(write)e(data)h(to)h
  373. Fj(next_out)p Fl(.)49 b(Because)36 b(the)e(output)f(bu13er)g
  374. (supplied)150 2199 y(b)m(y)e(the)h(user)e(can)i(b)s(e)f(arbitrarily)d
  375. (small,)j(the)g(14nishing-up)d(op)s(eration)i(cannot)i(necessarily)e
  376. (b)s(e)h(done)150 2309 y(with)e(a)i(single)e(call)h(of)g
  377. Fj(bzCompress)p Fl(.)150 2466 y(Instead,)j(the)g(calling)e(program)i
  378. (passes)f Fj(BZ_FINISH)e Fl(as)j(an)g(action)g(to)g Fj(bzCompress)p
  379. Fl(.)45 b(This)31 b(c)m(hanges)150 2575 y(the)36 b(stream's)f(state)i
  380. (to)f(FINISHING.)g(An)m(y)f(remaining)f(input)f((ie,)k
  381. Fj(next_in[0)28 b(..)i(avail_in-1])p Fl())150 2685 y(is)e(compressed)g
  382. (and)h(transferred)e(to)j(the)f(output)f(bu13er.)40
  383. b(T)-8 b(o)29 b(do)g(this,)f Fj(bzCompress)e Fl(m)m(ust)j(b)s(e)f
  384. (called)150 2794 y(rep)s(eatedly)40 b(un)m(til)f(all)g(the)i(output)f
  385. (has)h(b)s(een)e(consumed.)71 b(A)m(t)42 b(that)f(p)s(oin)m(t,)h
  386. Fj(bzCompress)c Fl(returns)150 2904 y Fj(BZ_STREAM_END)p
  387. Fl(,)33 b(and)i(the)g(stream's)h(state)g(is)e(set)i(bac)m(k)g(to)g
  388. (IDLE.)f Fj(bzCompressEnd)d Fl(should)h(then)150 3014
  389. y(b)s(e)d(called.)150 3170 y(Just)25 b(to)i(mak)m(e)g(sure)e(the)i
  390. (calling)d(program)i(do)s(es)g(not)g(c)m(heat,)i(the)f(library)c(mak)m
  391. (es)k(a)f(note)h(of)f Fj(avail_in)150 3280 y Fl(at)f(the)g(time)g(of)f
  392. (the)h(14rst)f(call)g(to)i Fj(bzCompress)21 b Fl(whic)m(h)j(has)g
  393. Fj(BZ_FINISH)e Fl(as)j(an)g(action)g((ie,)h(at)f(the)g(time)150
  394. 3390 y(the)h(program)g(has)g(announced)f(its)g(in)m(ten)m(tion)h(to)g
  395. (not)h(supply)c(an)m(y)k(more)f(input).)37 b(By)27 b(comparing)e(this)
  396. 150 3499 y(v)-5 b(alue)23 b(with)f(that)i(of)g Fj(avail_in)d
  397. Fl(o)m(v)m(er)k(subsequen)m(t)e(calls)g(to)h Fj(bzCompress)p
  398. Fl(,)e(the)i(library)d(can)j(detect)h(an)m(y)150 3609
  399. y(attempts)32 b(to)g(slip)d(in)g(more)j(data)f(to)h(compress.)42
  400. b(An)m(y)32 b(calls)e(for)h(whic)m(h)e(this)h(is)g(detected)j(will)28
  401. b(return)150 3718 y Fj(BZ_SEQUENCE_ERROR)p Fl(.)36 b(This)29
  402. b(indicates)g(a)i(programming)e(mistak)m(e)i(whic)m(h)e(should)f(b)s(e)
  403. i(corrected.)150 3875 y(Instead)21 b(of)f(asking)h(to)g(14nish,)g
  404. (the)g(calling)e(program)h(ma)m(y)i(ask)f Fj(bzCompress)c
  405. Fl(to)22 b(tak)m(e)g(all)e(the)h(remaining)150 3985 y(input,)32
  406. b(compress)h(it)g(and)g(terminate)g(the)h(curren)m(t)f((Burro)m
  407. (ws-Wheeler))g(compression)g(blo)s(c)m(k.)49 b(This)150
  408. 4094 y(could)23 b(b)s(e)h(useful)f(for)h(error)g(con)m(trol)h(purp)s
  409. (oses.)37 b(The)24 b(mec)m(hanism)f(is)h(analogous)h(to)g(that)g(for)f
  410. (14nishing:)150 4204 y(call)j Fj(bzCompress)e Fl(with)h(an)i(action)f
  411. (of)h Fj(BZ_FLUSH)p Fl(,)e(remo)m(v)m(e)j(output)f(data,)h(and)e(p)s
  412. (ersist)f(with)g(the)i Fj(BZ_)150 4314 y(FLUSH)d Fl(action)i(un)m(til)d
  413. (the)j(v)-5 b(alue)26 b Fj(BZ_RUN)e Fl(is)i(returned.)38
  414. b(As)26 b(with)f(14nishing,)f Fj(bzCompress)g Fl(detects)k(an)m(y)150
  415. 4423 y(attempt)j(to)h(pro)m(vide)d(more)i(input)d(data)j(once)g(the)g
  416. (15ush)d(has)j(b)s(egun.)150 4580 y(Once)f(the)h(15ush)e(is)g
  417. (complete,)i(the)g(stream)f(returns)g(to)h(the)f(normal)g(R)m(UNNING)h
  418. (state.)150 4737 y(This)f(all)h(sounds)g(prett)m(y)h(complex,)h(but)e
  419. (isn't)g(really)-8 b(.)45 b(Here's)33 b(a)f(table)g(whic)m(h)f(sho)m
  420. (ws)h(whic)m(h)f(actions)150 4846 y(are)e(allo)m(w)m(able)f(in)f(eac)m
  421. (h)j(state,)g(what)f(action)g(will)c(b)s(e)j(tak)m(en,)j(what)d(the)h
  422. (next)f(state)i(is,)e(and)g(what)h(the)150 4956 y(non-error)h(return)f
  423. (v)-5 b(alues)29 b(are.)41 b(Note)32 b(that)e(y)m(ou)h(can't)g
  424. (explicitly)d(ask)i(what)g(state)i(the)e(stream)h(is)e(in,)150
  425. 5066 y(but)h(nor)g(do)g(y)m(ou)h(need)f(to)h({)g(it)e(can)i(b)s(e)f
  426. (inferred)e(from)i(the)h(v)-5 b(alues)29 b(returned)h(b)m(y)g
  427. Fj(bzCompress)p Fl(.)390 5217 y(IDLE/)p Fj(any)572 5320
  428. y Fl(Illegal.)60 b(IDLE)30 b(state)i(only)d(exists)h(after)h
  429. Fj(bzCompressEnd)c Fl(or)p eop
  430. %%Page: 17 18
  431. 17 17 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  432. b(with)g Fj(libbzip2)1881 b Fl(17)572 366 y(b)s(efore)30
  433. b Fj(bzCompressInit)p Fl(.)572 470 y(Return)f(v)-5 b(alue)30
  434. b(=)g Fj(BZ_SEQUENCE_ERROR)390 678 y Fl(R)m(UNNING/)p
  435. Fj(BZ_RUN)572 782 y Fl(Compress)f(from)h Fj(next_in)f
  436. Fl(to)i Fj(next_out)d Fl(as)i(m)m(uc)m(h)h(as)f(p)s(ossible.)572
  437. 885 y(Next)h(state)h(=)e(R)m(UNNING)572 989 y(Return)f(v)-5
  438. b(alue)30 b(=)g Fj(BZ_RUN_OK)390 1197 y Fl(R)m(UNNING/)p
  439. Fj(BZ_FLUSH)572 1300 y Fl(Remem)m(b)s(er)g(curren)m(t)g(v)-5
  440. b(alue)30 b(of)g Fj(next_in)p Fl(.)59 b(Compress)30 b(from)g
  441. Fj(next_in)572 1404 y Fl(to)h Fj(next_out)d Fl(as)j(m)m(uc)m(h)f(as)h
  442. (p)s(ossible,)d(but)i(do)g(not)g(accept)i(an)m(y)f(more)f(input.)572
  443. 1508 y(Next)h(state)h(=)e(FLUSHING)572 1612 y(Return)f(v)-5
  444. b(alue)30 b(=)g Fj(BZ_FLUSH_OK)390 1819 y Fl(R)m(UNNING/)p
  445. Fj(BZ_FINISH)572 1923 y Fl(Remem)m(b)s(er)g(curren)m(t)g(v)-5
  446. b(alue)30 b(of)g Fj(next_in)p Fl(.)59 b(Compress)30 b(from)g
  447. Fj(next_in)572 2027 y Fl(to)h Fj(next_out)d Fl(as)j(m)m(uc)m(h)f(as)h
  448. (p)s(ossible,)d(but)i(do)g(not)g(accept)i(an)m(y)f(more)f(input.)572
  449. 2131 y(Next)h(state)h(=)e(FINISHING)572 2234 y(Return)f(v)-5
  450. b(alue)30 b(=)g Fj(BZ_FINISH_OK)390 2442 y Fl(FLUSHING/)p
  451. Fj(BZ_FLUSH)572 2546 y Fl(Compress)f(from)h Fj(next_in)f
  452. Fl(to)i Fj(next_out)d Fl(as)i(m)m(uc)m(h)h(as)f(p)s(ossible,)572
  453. 2650 y(but)f(do)i(not)f(accept)i(an)m(y)f(more)f(input.)572
  454. 2753 y(If)g(all)f(the)i(existing)e(input)f(has)i(b)s(een)g(used)g(up)f
  455. (and)h(all)f(compressed)572 2857 y(output)h(has)g(b)s(een)g(remo)m(v)m
  456. (ed)663 2961 y(Next)h(state)h(=)e(R)m(UNNING;)i(Return)d(v)-5
  457. b(alue)30 b(=)g Fj(BZ_RUN_OK)572 3065 y Fl(else)663 3168
  458. y(Next)h(state)h(=)e(FLUSHING;)h(Return)e(v)-5 b(alue)30
  459. b(=)g Fj(BZ_FLUSH_OK)390 3376 y Fl(FLUSHING/other)572
  460. 3480 y(Illegal.)572 3584 y(Return)f(v)-5 b(alue)30 b(=)g
  461. Fj(BZ_SEQUENCE_ERROR)390 3791 y Fl(FINISHING/)p Fj(BZ_FINISH)572
  462. 3895 y Fl(Compress)f(from)h Fj(next_in)f Fl(to)i Fj(next_out)d
  463. Fl(as)i(m)m(uc)m(h)h(as)f(p)s(ossible,)572 3999 y(but)f(to)j(not)e
  464. (accept)i(an)m(y)f(more)f(input.)572 4102 y(If)g(all)f(the)i(existing)e
  465. (input)f(has)i(b)s(een)g(used)g(up)f(and)h(all)f(compressed)572
  466. 4206 y(output)h(has)g(b)s(een)g(remo)m(v)m(ed)663 4310
  467. y(Next)h(state)h(=)e(IDLE;)g(Return)g(v)-5 b(alue)30
  468. b(=)g Fj(BZ_STREAM_END)572 4414 y Fl(else)663 4518 y(Next)h(state)h(=)e
  469. (FINISHING;)g(Return)g(v)-5 b(alue)30 b(=)g Fj(BZ_FINISHING)390
  470. 4725 y Fl(FINISHING/other)572 4829 y(Illegal.)572 4933
  471. y(Return)f(v)-5 b(alue)30 b(=)g Fj(BZ_SEQUENCE_ERROR)150
  472. 5090 y Fl(That)24 b(still)f(lo)s(oks)g(complicated?)39
  473. b(W)-8 b(ell,)25 b(fair)f(enough.)38 b(The)24 b(usual)f(sequence)i(of)f
  474. (calls)g(for)g(compressing)150 5199 y(a)31 b(load)f(of)g(data)h(is:)p
  475. eop
  476. %%Page: 18 19
  477. 18 18 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  478. b(with)g Fj(libbzip2)1881 b Fl(18)225 366 y Fi(17)60
  479. b Fl(Get)31 b(started)g(with)e Fj(bzCompressInit)p Fl(.)225
  480. 496 y Fi(17)60 b Fl(Sho)m(v)m(el)54 b(data)i(in)d(and)h(shlurp)d(out)
  481. k(its)f(compressed)g(form)g(using)f(zero)i(or)g(more)f(calls)g(of)330
  482. 605 y Fj(bzCompress)28 b Fl(with)h(action)h(=)g Fj(BZ_RUN)p
  483. Fl(.)225 734 y Fi(17)60 b Fl(Finish)39 b(up.)71 b(Rep)s(eatedly)40
  484. b(call)g Fj(bzCompress)e Fl(with)i(action)h(=)g Fj(BZ_FINISH)p
  485. Fl(,)g(cop)m(ying)g(out)g(the)330 844 y(compressed)30
  486. b(output,)g(un)m(til)f Fj(BZ_STREAM_END)e Fl(is)i(returned.)225
  487. 973 y Fi(17)60 b Fl(Close)30 b(up)f(and)h(go)h(home.)41
  488. b(Call)29 b Fj(bzCompressEnd)p Fl(.)150 1149 y(If)23
  489. b(the)h(data)h(y)m(ou)f(w)m(an)m(t)h(to)f(compress)g(14ts)f(in)m(to)h
  490. (y)m(our)g(input)e(bu13er)h(all)f(at)j(once,)h(y)m(ou)e(can)g(skip)f
  491. (the)h(calls)150 1259 y(of)31 b Fj(bzCompress)c(()j(...,)f(BZ_RUN)g
  492. ())h Fl(and)g(just)g(do)g(the)g Fj(bzCompress)e(()i(...,)f(BZ_FINISH)
  493. f())i Fl(calls.)150 1416 y(All)39 b(required)f(memory)i(is)g(allo)s
  494. (cated)g(b)m(y)g Fj(bzCompressInit)p Fl(.)67 b(The)39
  495. b(compression)g(library)f(can)j(ac-)150 1525 y(cept)e(an)m(y)h(data)f
  496. (at)h(all)e((ob)m(viously).)65 b(So)39 b(y)m(ou)g(shouldn't)e(get)k
  497. (an)m(y)e(error)f(return)g(v)-5 b(alues)38 b(from)h(the)150
  498. 1635 y Fj(bzCompress)29 b Fl(calls.)43 b(If)31 b(y)m(ou)h(do,)f(they)h
  499. (will)d(b)s(e)i Fj(BZ_SEQUENCE_ERROR)p Fl(,)c(and)k(indicate)f(a)i(bug)
  500. f(in)f(y)m(our)150 1744 y(programming.)150 1901 y(T)-8
  501. b(rivial)28 b(other)j(p)s(ossible)d(return)h(v)-5 b(alues:)572
  502. 2052 y Fj(BZ_PARAM_ERROR)663 2156 y Fl(if)29 b Fj(strm)g
  503. Fl(is)h Fj(NULL)p Fl(,)f(or)i Fj(strm->s)d Fl(is)h Fj(NULL)150
  504. 2392 y Ff(3.3.3)63 b Fe(bzCompressEnd)390 2579 y Fj(int)47
  505. b(bzCompressEnd)d(()k(bz_stream)d(*strm)h();)150 2735
  506. y Fl(Releases)31 b(all)e(memory)h(asso)s(ciated)h(with)e(a)i
  507. (compression)e(stream.)150 2892 y(P)m(ossible)g(return)h(v)-5
  508. b(alues:)481 3043 y Fj(BZ_PARAM_ERROR)117 b Fl(if)30
  509. b Fj(strm)f Fl(is)g Fj(NULL)g Fl(or)i Fj(strm->s)d Fl(is)i
  510. Fj(NULL)481 3147 y(BZ_OK)120 b Fl(otherwise)150 3383
  511. y Ff(3.3.4)63 b Fe(bzDecompressInit)390 3570 y Fj(int)47
  512. b(bzDecompressInit)c(()48 b(bz_stream)d(*strm,)h(int)h(verbosity,)e
  513. (int)i(small)f();)150 3726 y Fl(Prepares)28 b(for)h(decompression.)39
  514. b(As)29 b(with)f Fj(bzCompressInit)p Fl(,)d(a)k Fj(bz_stream)e
  515. Fl(record)h(should)f(b)s(e)h(allo-)150 3836 y(cated)i(and)f
  516. (initialised)d(b)s(efore)j(the)g(call.)40 b(Fields)28
  517. b Fj(bzalloc)p Fl(,)f Fj(bzfree)h Fl(and)h Fj(opaque)e
  518. Fl(should)h(b)s(e)g(set)i(if)f(a)150 3946 y(custom)i(memory)g(allo)s
  519. (cator)h(is)e(required,)g(or)h(made)g Fj(NULL)f Fl(for)h(the)g(normal)f
  520. Fj(malloc)p Fl(/)p Fj(free)f Fl(routines.)150 4055 y(Up)s(on)24
  521. b(return,)h(the)g(in)m(ternal)f(state)i(will)c(ha)m(v)m(e)k(b)s(een)f
  522. (initialised,)d(and)i Fj(total_in)f Fl(and)h Fj(total_out)f
  523. Fl(will)150 4165 y(b)s(e)30 b(zero.)150 4322 y(F)-8 b(or)31
  524. b(the)g(meaning)e(of)i(parameter)g Fj(verbosity)p Fl(,)d(see)j
  525. Fj(bzCompressInit)p Fl(.)150 4478 y(If)e Fj(small)e Fl(is)h(nonzero,)i
  526. (the)f(library)e(will)f(use)j(an)g(alternativ)m(e)h(decompression)e
  527. (algorithm)g(whic)m(h)f(uses)150 4588 y(less)c(memory)g(but)g(at)h(the)
  528. g(cost)h(of)e(decompressing)g(more)g(slo)m(wly)g((roughly)f(sp)s
  529. (eaking,)i(half)f(the)h(sp)s(eed,)150 4698 y(but)34 b(the)i(maxim)m(um)
  530. d(memory)i(requiremen)m(t)g(drops)e(to)j(around)e(2300k).)57
  531. b(See)35 b(Chapter)g(2)g(for)g(more)150 4807 y(information)29
  532. b(on)h(memory)g(managemen)m(t.)150 4964 y(Note)24 b(that)f(the)g(amoun)
  533. m(t)g(of)f(memory)h(needed)f(to)h(decompress)g(a)g(stream)f(cannot)i(b)
  534. s(e)d(determined)h(un)m(til)150 5074 y(the)38 b(stream's)g(header)f
  535. (has)g(b)s(een)g(read,)i(so)f(ev)m(en)g(if)f Fj(bzDecompressInit)c
  536. Fl(succeeds,)40 b(a)e(subsequen)m(t)150 5183 y Fj(bzDecompress)27
  537. b Fl(could)i(fail)g(with)h Fj(BZ_MEM_ERROR)p Fl(.)150
  538. 5340 y(P)m(ossible)f(return)h(v)-5 b(alues:)p eop
  539. %%Page: 19 20
  540. 19 19 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  541. b(with)g Fj(libbzip2)1881 b Fl(19)572 366 y Fj(BZ_PARAM_ERROR)663
  542. 470 y Fl(if)29 b Fj((small)46 b(!=)h(0)h(&&)f(small)f(!=)h(1))663
  543. 574 y Fl(or)30 b Fj((verbosity)45 b(<)j(0)f(||)g(verbosity)e(>)j(4))
  544. 572 678 y(BZ_MEM_ERROR)663 782 y Fl(if)29 b(insu16cien)m(t)g(memory)h
  545. (is)f(a)m(v)-5 b(ailable)150 938 y(Allo)m(w)m(able)30
  546. b(next)g(actions:)572 1089 y Fj(bzDecompress)663 1193
  547. y Fl(if)f Fj(BZ_OK)g Fl(w)m(as)i(returned)572 1297 y(no)f(sp)s
  548. (eci14c)f(action)i(required)e(in)g(case)i(of)g(error)150
  549. 1591 y Ff(3.3.5)63 b Fe(bzDecompress)390 1777 y Fj(int)47
  550. b(bzDecompress)d(()k(bz_stream)d(*strm)h();)150 1934
  551. y Fl(Pro)m(vides)24 b(more)g(input)f(and/out)h(output)g(bu13er)g
  552. (space)h(for)f(the)g(library)-8 b(.)37 b(The)24 b(caller)g(main)m
  553. (tains)f(input)150 2044 y(and)30 b(output)g(bu13ers,)f(and)h(uses)g
  554. Fj(bzDecompress)d Fl(to)k(transfer)f(data)h(b)s(et)m(w)m(een)g(them.)
  555. 150 2201 y(Before)46 b(eac)m(h)h(call)e(to)h Fj(bzDecompress)p
  556. Fl(,)g Fj(next_in)d Fl(should)g(p)s(oin)m(t)i(at)h(the)f(compressed)g
  557. (data,)51 b(and)150 2310 y Fj(avail_in)34 b Fl(should)h(indicate)g(ho)m
  558. (w)i(man)m(y)g(b)m(ytes)g(the)f(library)e(ma)m(y)k(read.)59
  559. b Fj(bzDecompress)33 b Fl(up)s(dates)150 2420 y Fj(next_in)p
  560. Fl(,)c Fj(avail_in)f Fl(and)i Fj(total_in)e Fl(to)j(re15ect)g(the)f
  561. (n)m(um)m(b)s(er)f(of)i(b)m(ytes)g(it)f(has)g(read.)150
  562. 2577 y(Similarly)-8 b(,)37 b Fj(next_out)f Fl(should)g(p)s(oin)m(t)i
  563. (to)g(a)h(bu13er)e(in)g(whic)m(h)g(the)i(uncompressed)e(output)g(is)h
  564. (to)h(b)s(e)150 2686 y(placed,)23 b(with)d Fj(avail_out)f
  565. Fl(indicating)g(ho)m(w)i(m)m(uc)m(h)h(output)f(space)h(is)e(a)m(v)-5
  566. b(ailable.)37 b Fj(bzCompress)19 b Fl(up)s(dates)150
  567. 2796 y Fj(next_out)p Fl(,)28 b Fj(avail_out)g Fl(and)i
  568. Fj(total_out)e Fl(to)j(re15ect)g(the)f(n)m(um)m(b)s(er)g(of)g(b)m
  569. (ytes)h(output.)150 2953 y(Y)-8 b(ou)53 b(ma)m(y)h(pro)m(vide)e(and)g
  570. (remo)m(v)m(e)j(as)e(little)e(or)i(as)h(m)m(uc)m(h)e(data)i(as)f(y)m
  571. (ou)g(lik)m(e)g(on)f(eac)m(h)j(call)d(of)150 3062 y Fj(bzDecompress)p
  572. Fl(.)72 b(In)41 b(the)i(limit,)g(it)e(is)g(acceptable)i(to)g(supply)c
  573. (and)j(remo)m(v)m(e)h(data)g(one)f(b)m(yte)h(at)g(a)150
  574. 3172 y(time,)c(although)e(this)g(w)m(ould)f(b)s(e)h(terribly)e
  575. (ine16cien)m(t.)62 b(Y)-8 b(ou)38 b(should)d(alw)m(a)m(ys)j(ensure)f
  576. (that)h(at)h(least)150 3281 y(one)31 b(b)m(yte)g(of)f(output)g(space)h
  577. (is)f(a)m(v)-5 b(ailable)29 b(at)i(eac)m(h)h(call.)150
  578. 3438 y(Use)f(of)f Fj(bzDecompress)d Fl(is)j(simpler)e(than)i
  579. Fj(bzCompress)p Fl(.)150 3595 y(Y)-8 b(ou)49 b(should)d(pro)m(vide)h
  580. (input)g(and)g(remo)m(v)m(e)j(output)e(as)g(describ)s(ed)e(ab)s(o)m(v)m
  581. (e,)54 b(and)48 b(rep)s(eatedly)g(call)150 3705 y Fj(bzDecompress)35
  582. b Fl(un)m(til)i Fj(BZ_STREAM_END)e Fl(is)j(returned.)64
  583. b(App)s(earance)39 b(of)g Fj(BZ_STREAM_END)c Fl(denotes)150
  584. 3814 y(that)d Fj(bzDecompress)c Fl(has)k(detected)g(the)g(logical)f
  585. (end)g(of)h(the)f(compressed)h(stream.)44 b Fj(bzDecompress)150
  586. 3924 y Fl(will)18 b(not)k(pro)s(duce)e Fj(BZ_STREAM_END)d
  587. Fl(un)m(til)i(all)h(output)h(data)h(has)f(b)s(een)f(placed)h(in)m(to)g
  588. (the)g(output)g(bu13er,)150 4033 y(so)27 b(once)h Fj(BZ_STREAM_END)23
  589. b Fl(app)s(ears,)k(y)m(ou)g(are)h(guaran)m(teed)f(to)h(ha)m(v)m(e)g(a)m
  590. (v)-5 b(ailable)26 b(all)g(the)h(decompressed)150 4143
  591. y(output,)j(and)g Fj(bzDecompressEnd)c Fl(can)31 b(safely)f(b)s(e)g
  592. (called.)150 4300 y(If)i(case)i(of)f(an)g(error)f(return)g(v)-5
  593. b(alue,)33 b(y)m(ou)h(should)c(call)j Fj(bzDecompressEnd)28
  594. b Fl(to)34 b(clean)f(up)e(and)i(release)150 4409 y(memory)-8
  595. b(.)150 4566 y(P)m(ossible)29 b(return)h(v)-5 b(alues:)572
  596. 4717 y Fj(BZ_PARAM_ERROR)663 4821 y Fl(if)29 b Fj(strm)g
  597. Fl(is)h Fj(NULL)f Fl(or)h Fj(strm->s)f Fl(is)g Fj(NULL)663
  598. 4925 y Fl(or)h Fj(strm->avail_out)44 b(<)j(1)572 5029
  599. y(BZ_DATA_ERROR)663 5132 y Fl(if)29 b(a)i(data)g(in)m(tegrit)m(y)f
  600. (error)g(is)g(detected)h(in)e(the)i(compressed)f(stream)572
  601. 5236 y Fj(BZ_DATA_ERROR_MAGIC)663 5340 y Fl(if)f(the)i(compressed)f
  602. (stream)g(do)s(esn't)h(b)s(egin)e(with)g(the)h(righ)m(t)g(magic)h(b)m
  603. (ytes)p eop
  604. %%Page: 20 21
  605. 20 20 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  606. b(with)g Fj(libbzip2)1881 b Fl(20)572 366 y Fj(BZ_MEM_ERROR)663
  607. 470 y Fl(if)29 b(there)i(w)m(asn't)f(enough)h(memory)f(a)m(v)-5
  608. b(ailable)572 574 y Fj(BZ_STREAM_END)663 678 y Fl(if)29
  609. b(the)i(logical)e(end)h(of)h(the)f(data)h(stream)g(w)m(as)g(detected)g
  610. (and)f(all)663 782 y(output)g(in)f(has)h(b)s(een)g(consumed,)f(eg)j
  611. Fj(s->avail_out)44 b(>)k(0)572 885 y(BZ_OK)663 989 y
  612. Fl(otherwise)150 1146 y(Allo)m(w)m(able)30 b(next)g(actions:)572
  613. 1297 y Fj(bzDecompress)663 1401 y Fl(if)f Fj(BZ_OK)g
  614. Fl(w)m(as)i(returned)572 1505 y Fj(bzDecompressEnd)663
  615. 1608 y Fl(otherwise)150 1864 y Ff(3.3.6)63 b Fe(bzDecompressEnd)390
  616. 2050 y Fj(int)47 b(bzDecompressEnd)d(()j(bz_stream)e(*strm)i();)150
  617. 2207 y Fl(Releases)31 b(all)e(memory)h(asso)s(ciated)h(with)e(a)i
  618. (decompression)e(stream.)150 2364 y(P)m(ossible)g(return)h(v)-5
  619. b(alues:)572 2515 y Fj(BZ_PARAM_ERROR)663 2619 y Fl(if)29
  620. b Fj(strm)g Fl(is)h Fj(NULL)f Fl(or)h Fj(strm->s)f Fl(is)g
  621. Fj(NULL)572 2723 y(BZ_OK)663 2826 y Fl(otherwise)150
  622. 2983 y(Allo)m(w)m(able)h(next)g(actions:)572 3134 y(None.)150
  623. 3427 y Fk(3.4)68 b(High-lev)l(el)47 b(in)l(terface)150
  624. 3620 y Fl(This)35 b(in)m(terface)j(pro)m(vides)d(functions)h(for)g
  625. (reading)g(and)h(writing)e Fj(bzip2)g Fl(format)i(14les.)59
  626. b(First,)39 b(some)150 3729 y(general)30 b(p)s(oin)m(ts.)225
  627. 3886 y Fi(17)60 b Fl(All)35 b(of)h(the)g(functions)e(tak)m(e)k(an)e
  628. Fj(int*)f Fl(14rst)g(argumen)m(t,)j Fj(bzerror)p Fl(.)56
  629. b(After)36 b(eac)m(h)h(call,)g Fj(bzerror)330 3996 y
  630. Fl(should)23 b(b)s(e)i(consulted)g(14rst)g(to)h(determine)e(the)i
  631. (outcome)h(of)e(the)h(call.)38 b(If)25 b Fj(bzerror)f
  632. Fl(is)g Fj(BZ_OK)p Fl(,)i(the)330 4105 y(call)35 b(completed)g
  633. (successfully)-8 b(,)36 b(and)f(only)g(then)g(should)f(the)h(return)g
  634. (v)-5 b(alue)35 b(of)h(the)f(function)g((if)330 4215
  635. y(an)m(y))30 b(b)s(e)f(consulted.)39 b(If)29 b Fj(bzerror)e
  636. Fl(is)h Fj(BZ_IO_ERROR)p Fl(,)f(there)i(w)m(as)h(an)f(error)g
  637. (reading/writing)e(the)330 4324 y(underlying)32 b(compressed)j(14le,)
  638. h(and)f(y)m(ou)h(should)d(then)i(consult)g Fj(errno)p
  639. Fl(/)p Fj(perror)e Fl(to)j(determine)330 4434 y(the)i(cause)g(of)g(the)
  640. g(di16cult)m(y)-8 b(.)61 b Fj(bzerror)36 b Fl(ma)m(y)i(also)g(b)s(e)f
  641. (set)h(to)g(v)-5 b(arious)37 b(other)h(v)-5 b(alues;)41
  642. b(precise)330 4544 y(details)29 b(are)i(giv)m(en)g(on)f(a)h(p)s
  643. (er-function)d(basis)h(b)s(elo)m(w.)225 4682 y Fi(17)60
  644. b Fl(If)40 b Fj(bzerror)f Fl(indicates)g(an)i(error)f((ie,)j(an)m
  645. (ything)d(except)h Fj(BZ_OK)f Fl(and)g Fj(BZ_STREAM_END)p
  646. Fl(),)g(y)m(ou)330 4792 y(should)19 b(immediately)h(call)h
  647. Fj(bzReadClose)d Fl((or)k Fj(bzWriteClose)p Fl(,)e(dep)s(ending)f(on)i
  648. (whether)g(y)m(ou)h(are)330 4902 y(attempting)g(to)h(read)f(or)g(to)h
  649. (write))e(to)i(free)f(up)f(all)g(resources)h(asso)s(ciated)h(with)d
  650. (the)j(stream.)38 b(Once)330 5011 y(an)24 b(error)g(has)h(b)s(een)e
  651. (indicated,)i(b)s(eha)m(viour)e(of)i(all)e(calls)h(except)h
  652. Fj(bzReadClose)d Fl(()p Fj(bzWriteClose)p Fl())330
  653. 5121 y(is)36 b(unde14ned.)56 b(The)36 b(implication)e(is)i(that)h
  654. ((1))g Fj(bzerror)e Fl(should)f(b)s(e)i(c)m(hec)m(k)m(ed)j(after)e
  655. (eac)m(h)g(call,)330 5230 y(and)g((2))h(if)e Fj(bzerror)f
  656. Fl(indicates)i(an)g(error,)i Fj(bzReadClose)34 b Fl(()p
  657. Fj(bzWriteClose)p Fl())g(should)i(then)h(b)s(e)330 5340
  658. y(called)30 b(to)h(clean)f(up.)p eop
  659. %%Page: 21 22
  660. 21 21 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  661. b(with)g Fj(libbzip2)1881 b Fl(21)225 366 y Fi(17)60
  662. b Fl(The)42 b Fj(FILE*)f Fl(argumen)m(ts)i(passed)g(to)g
  663. Fj(bzReadOpen)p Fl(/)p Fj(bzWriteOpen)37 b Fl(should)k(b)s(e)h(set)h
  664. (to)h(binary)330 476 y(mo)s(de.)85 b(Most)46 b(Unix)f(systems)g(will)e
  665. (do)i(this)f(b)m(y)h(default,)k(but)44 b(other)i(platforms,)i
  666. (including)330 586 y(Windo)m(ws)42 b(and)g(Mac,)48 b(will)40
  667. b(not.)79 b(If)43 b(y)m(ou)g(omit)g(this,)i(y)m(ou)f(ma)m(y)f(encoun)m
  668. (ter)h(problems)d(when)330 695 y(mo)m(ving)30 b(co)s(de)h(to)g(new)f
  669. (platforms.)225 858 y Fi(17)60 b Fl(Memory)23 b(allo)s(cation)f
  670. (requests)h(are)g(handled)e(b)m(y)i Fj(malloc)p Fl(/)p
  671. Fj(free)p Fl(.)36 b(A)m(t)23 b(presen)m(t)g(there)g(is)f(no)h(facilit)m
  672. (y)330 967 y(for)40 b(user-de14ned)e(memory)i(allo)s(cators)g(in)f
  673. (the)h(14le)g(I/O)g(functions)e((could)i(easily)f(b)s(e)g(added,)330
  674. 1077 y(though).)150 1379 y Ff(3.4.1)63 b Fe(bzReadOpen)533
  675. 1566 y Fj(typedef)46 b(void)h(BZFILE;)533 1773 y(BZFILE)f(*bzReadOpen)f
  676. (()i(int)g(*bzerror,)f(FILE)g(*f,)1535 1877 y(int)h(small,)f(int)h
  677. (verbosity,)1535 1981 y(void)g(*unused,)f(int)h(nUnused)e();)150
  678. 2138 y Fl(Prepare)29 b(to)g(read)g(compressed)f(data)i(from)e(14le)g
  679. (handle)f Fj(f)p Fl(.)40 b Fj(f)29 b Fl(should)d(refer)j(to)h(a)f
  680. (14le)f(whic)m(h)f(has)i(b)s(een)150 2247 y(op)s(ened)h(for)h
  681. (reading,)f(and)h(for)f(whic)m(h)g(the)h(error)g(indicator)e(()p
  682. Fj(ferror(f))p Fl()is)f(not)k(set.)42 b(If)31 b Fj(small)e
  683. Fl(is)h(1,)150 2357 y(the)h(library)d(will)f(try)j(to)i(decompress)e
  684. (using)f(less)g(memory)-8 b(,)31 b(at)g(the)g(exp)s(ense)f(of)g(sp)s
  685. (eed.)150 2514 y(F)-8 b(or)26 b(reasons)f(explained)e(b)s(elo)m(w,)j
  686. Fj(bzRead)d Fl(will)g(decompress)i(the)g Fj(nUnused)e
  687. Fl(b)m(ytes)j(starting)f(at)g Fj(unused)p Fl(,)150 2623
  688. y(b)s(efore)k(starting)g(to)h(read)f(from)g(the)g(14le)g
  689. Fj(f)p Fl(.)40 b(A)m(t)30 b(most)g Fj(BZ_MAX_UNUSED)25
  690. b Fl(b)m(ytes)30 b(ma)m(y)g(b)s(e)f(supplied)d(lik)m(e)150
  691. 2733 y(this.)53 b(If)34 b(this)g(facilit)m(y)g(is)g(not)h(required,)f
  692. (y)m(ou)h(should)e(pass)h Fj(NULL)g Fl(and)g Fj(0)g Fl(for)h
  693. Fj(unused)e Fl(and)h(n)p Fj(Unused)150 2842 y Fl(resp)s(ectiv)m(ely)-8
  694. b(.)150 2999 y(F)g(or)31 b(the)g(meaning)e(of)i(parameters)g
  695. Fj(small)e Fl(and)g Fj(verbosity)p Fl(,)f(see)j Fj(bzDecompressInit)p
  696. Fl(.)150 3156 y(The)k(amoun)m(t)g(of)g(memory)g(needed)g(to)g
  697. (decompress)g(a)h(14le)e(cannot)h(b)s(e)g(determined)e(un)m(til)h
  698. (the)h(14le's)150 3266 y(header)g(has)g(b)s(een)f(read.)55
  699. b(So)35 b(it)g(is)f(p)s(ossible)f(that)j Fj(bzReadOpen)c
  700. Fl(returns)i Fj(BZ_OK)g Fl(but)g(a)i(subsequen)m(t)150
  701. 3375 y(call)30 b(of)g Fj(bzRead)f Fl(will)f(return)h
  702. Fj(BZ_MEM_ERROR)p Fl(.)150 3532 y(P)m(ossible)g(assignmen)m(ts)h(to)h
  703. Fj(bzerror)p Fl(:)572 3683 y Fj(BZ_PARAM_ERROR)663 3787
  704. y Fl(if)e Fj(f)h Fl(is)g Fj(NULL)663 3891 y Fl(or)g Fj(small)f
  705. Fl(is)g(neither)h Fj(0)g Fl(nor)g Fj(1)663 3994 y Fl(or)g
  706. Fj((unused)46 b(==)h(NULL)g(&&)g(nUnused)f(!=)h(0))663
  707. 4098 y Fl(or)30 b Fj((unused)46 b(!=)h(NULL)g(&&)g(!(0)g(<=)g
  708. (nUnused)f(<=)h(BZ_MAX_UNUSED)))572 4202 y(BZ_IO_ERROR)663
  709. 4306 y Fl(if)29 b Fj(ferror(f))f Fl(is)h(nonzero)572
  710. 4409 y Fj(BZ_MEM_ERROR)663 4513 y Fl(if)g(insu16cien)m(t)g(memory)h
  711. (is)f(a)m(v)-5 b(ailable)572 4617 y Fj(BZ_OK)663 4721
  712. y Fl(otherwise.)150 4878 y(P)m(ossible)29 b(return)h(v)-5
  713. b(alues:)572 5029 y(P)m(oin)m(ter)31 b(to)g(an)f(abstract)h
  714. Fj(BZFILE)663 5132 y Fl(if)e Fj(bzerror)f Fl(is)i Fj(BZ_OK)572
  715. 5236 y(NULL)663 5340 y Fl(otherwise)p eop
  716. %%Page: 22 23
  717. 22 22 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  718. b(with)g Fj(libbzip2)1881 b Fl(22)150 366 y(Allo)m(w)m(able)30
  719. b(next)g(actions:)572 518 y Fj(bzRead)663 621 y Fl(if)f
  720. Fj(bzerror)f Fl(is)i Fj(BZ_OK)572 725 y(bzClose)663 829
  721. y Fl(otherwise)150 1103 y Ff(3.4.2)63 b Fe(bzRead)533
  722. 1290 y Fj(int)47 b(bzRead)f(()i(int)f(*bzerror,)e(BZFILE)h(*b,)h(void)
  723. f(*buf,)h(int)g(len)g();)150 1447 y Fl(Reads)35 b(up)f(to)h
  724. Fj(len)f Fl((uncompressed))h(b)m(ytes)g(from)f(the)h(compressed)g
  725. (14le)f Fj(b)g Fl(in)m(to)h(the)g(bu13er)f Fj(buf)p
  726. Fl(.)53 b(If)150 1556 y(the)30 b(read)f(w)m(as)h(successful,)f
  727. Fj(bzerror)e Fl(is)i(set)h(to)g Fj(BZ_OK)e Fl(and)h(the)h(n)m(um)m(b)s
  728. (er)e(of)i(b)m(ytes)g(read)f(is)g(returned.)150 1666
  729. y(If)k(the)g(logical)g(end-of-stream)h(w)m(as)g(detected,)i
  730. Fj(bzerror)31 b Fl(will)g(b)s(e)h(set)i(to)g Fj(BZ_STREAM_END)p
  731. Fl(,)d(and)i(the)150 1776 y(n)m(um)m(b)s(er)c(of)i(b)m(ytes)f(read)h
  732. (is)e(returned.)40 b(All)29 b(other)h Fj(bzerror)f Fl(v)-5
  733. b(alues)29 b(denote)i(an)g(error.)150 1932 y Fj(bzRead)f
  734. Fl(will)e(supply)h Fj(len)h Fl(b)m(ytes,)j(unless)c(the)j(logical)f
  735. (stream)g(end)g(is)f(detected)j(or)e(an)g(error)g(o)s(ccurs.)150
  736. 2042 y(Because)22 b(of)f(this,)h(it)f(is)f(p)s(ossible)e(to)k(detect)g
  737. (the)f(stream)h(end)e(b)m(y)h(observing)f(when)g(the)h(n)m(um)m(b)s(er)
  738. e(of)i(b)m(ytes)150 2152 y(returned)33 b(is)h(less)f(than)i(the)f(n)m
  739. (um)m(b)s(er)f(requested.)53 b(Nev)m(ertheless,)37 b(this)c(is)g
  740. (regarded)i(as)f(inadvisable;)150 2261 y(y)m(ou)d(should)d(instead)i(c)
  741. m(hec)m(k)i Fj(bzerror)c Fl(after)j(ev)m(ery)g(call)f(and)g(w)m(atc)m
  742. (h)h(out)g(for)f Fj(BZ_STREAM_END)p Fl(.)150 2418 y(In)m(ternally)-8
  743. b(,)37 b Fj(bzRead)d Fl(copies)i(data)h(from)f(the)g(compressed)g
  744. (14le)f(in)g(c)m(h)m(unks)h(of)h(size)f Fj(BZ_MAX_UNUSED)150
  745. 2528 y Fl(b)m(ytes)31 b(b)s(efore)e(decompressing)h(it.)40
  746. b(If)29 b(the)i(14le)e(con)m(tains)h(more)h(b)m(ytes)f(than)g
  747. (strictly)f(needed)h(to)h(reac)m(h)150 2637 y(the)26
  748. b(logical)g(end-of-stream,)i Fj(bzRead)c Fl(will)f(almost)j(certainly)g
  749. (read)g(some)g(of)g(the)g(trailing)f(data)h(b)s(efore)150
  750. 2747 y(signalling)31 b Fj(BZ_SEQUENCE_END)p Fl(.)45 b(T)-8
  751. b(o)34 b(collect)g(the)f(read)g(but)g(un)m(used)f(data)i(once)g
  752. Fj(BZ_SEQUENCE_END)150 2856 y Fl(has)c(app)s(eared,)g(call)g
  753. Fj(bzReadGetUnused)c Fl(immediately)j(b)s(efore)h Fj(bzReadClose)p
  754. Fl(.)150 3013 y(P)m(ossible)f(assignmen)m(ts)h(to)h Fj(bzerror)p
  755. Fl(:)572 3164 y Fj(BZ_PARAM_ERROR)663 3268 y Fl(if)e
  756. Fj(b)h Fl(is)g Fj(NULL)f Fl(or)h Fj(buf)g Fl(is)f Fj(NULL)g
  757. Fl(or)i Fj(len)46 b(<)i(0)572 3372 y(BZ_SEQUENCE_ERROR)663
  758. 3475 y Fl(if)29 b Fj(b)h Fl(w)m(as)h(op)s(ened)e(with)h
  759. Fj(bzWriteOpen)572 3579 y(BZ_IO_ERROR)663 3683 y Fl(if)f(there)i(is)e
  760. (an)h(error)g(reading)g(from)g(the)g(compressed)g(14le)572
  761. 3787 y Fj(BZ_UNEXPECTED_EOF)663 3891 y Fl(if)f(the)i(compressed)f
  762. (14le)f(ended)h(b)s(efore)g(the)g(logical)g(end-of-stream)h(w)m(as)g
  763. (detected)572 3994 y Fj(BZ_DATA_ERROR)663 4098 y Fl(if)e(a)i(data)g(in)
  764. m(tegrit)m(y)f(error)g(w)m(as)h(detected)h(in)d(the)h(compressed)g
  765. (stream)572 4202 y Fj(BZ_DATA_ERROR_MAGIC)663 4306 y
  766. Fl(if)f(the)i(stream)f(do)s(es)g(not)h(b)s(egin)e(with)g(the)i
  767. (requisite)e(header)h(b)m(ytes)h((ie,)f(is)g(not)663
  768. 4409 y(a)g Fj(bzip2)f Fl(data)i(14le).)61 b(This)28
  769. b(is)i(really)f(a)i(sp)s(ecial)e(case)i(of)g Fj(BZ_DATA_ERROR)p
  770. Fl(.)572 4513 y Fj(BZ_MEM_ERROR)663 4617 y Fl(if)e(insu16cien)m(t)g
  771. (memory)h(w)m(as)h(a)m(v)-5 b(ailable)572 4721 y Fj(BZ_STREAM_END)663
  772. 4825 y Fl(if)29 b(the)i(logical)e(end)h(of)h(stream)f(w)m(as)h
  773. (detected.)572 4928 y Fj(BZ_OK)663 5032 y Fl(otherwise.)150
  774. 5189 y(P)m(ossible)e(return)h(v)-5 b(alues:)572 5340
  775. y(n)m(um)m(b)s(er)29 b(of)h(b)m(ytes)h(read)p eop
  776. %%Page: 23 24
  777. 23 23 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  778. b(with)g Fj(libbzip2)1881 b Fl(23)663 366 y(if)29 b Fj(bzerror)f
  779. Fl(is)i Fj(BZ_OK)f Fl(or)h Fj(BZ_STREAM_END)572 470 y
  780. Fl(unde14ned)663 574 y(otherwise)150 731 y(Allo)m(w)m(able)g(next)g
  781. (actions:)572 882 y(collect)h(data)g(from)f Fj(buf)p
  782. Fl(,)f(then)h Fj(bzRead)f Fl(or)h Fj(bzReadClose)663
  783. 986 y Fl(if)f Fj(bzerror)f Fl(is)i Fj(BZ_OK)572 1089
  784. y Fl(collect)h(data)g(from)f Fj(buf)p Fl(,)f(then)h Fj(bzReadClose)e
  785. Fl(or)i Fj(bzReadGetUnused)663 1193 y Fl(if)f Fj(bzerror)f
  786. Fl(is)i Fj(BZ_SEQUENCE_END)572 1297 y(bzReadClose)663
  787. 1401 y Fl(otherwise)150 1642 y Ff(3.4.3)63 b Fe(bzReadGetUnused)533
  788. 1829 y Fj(void)47 b(bzReadGetUnused)c(()48 b(int*)f(bzerror,)e(BZFILE)
  789. h(*b,)1631 1932 y(void**)g(unused,)g(int*)g(nUnused)g();)150
  790. 2089 y Fl(Returns)36 b(data)i(whic)m(h)d(w)m(as)j(read)f(from)f(the)h
  791. (compressed)g(14le)f(but)g(w)m(as)h(not)h(needed)e(to)i(get)g(to)g
  792. (the)150 2199 y(logical)k(end-of-stream.)78 b Fj(*unused)41
  793. b Fl(is)h(set)h(to)g(the)g(address)f(of)g(the)h(data,)k(and)42
  794. b Fj(*nUnused)e Fl(to)k(the)150 2308 y(n)m(um)m(b)s(er)29
  795. b(of)i(b)m(ytes.)41 b Fj(*nUnused)28 b Fl(will)g(b)s(e)h(set)i(to)g(a)g
  796. (v)-5 b(alue)30 b(b)s(et)m(w)m(een)h Fj(0)f Fl(and)g
  797. Fj(BZ_MAX_UNUSED)d Fl(inclusiv)m(e.)150 2465 y(This)40
  798. b(function)h(ma)m(y)h(only)f(b)s(e)h(called)f(once)h
  799. Fj(bzRead)e Fl(has)i(signalled)e Fj(BZ_STREAM_END)e Fl(but)j(b)s(efore)
  800. 150 2575 y Fj(bzReadClose)p Fl(.)150 2732 y(P)m(ossible)29
  801. b(assignmen)m(ts)h(to)h Fj(bzerror)p Fl(:)572 2883 y
  802. Fj(BZ_PARAM_ERROR)663 2986 y Fl(if)e Fj(b)h Fl(is)g Fj(NULL)663
  803. 3090 y Fl(or)g Fj(unused)f Fl(is)g Fj(NULL)g Fl(or)i
  804. Fj(nUnused)d Fl(is)i Fj(NULL)572 3194 y(BZ_SEQUENCE_ERROR)663
  805. 3298 y Fl(if)f Fj(BZ_STREAM_END)e Fl(has)j(not)h(b)s(een)e(signalled)
  806. 663 3402 y(or)h(if)f Fj(b)h Fl(w)m(as)h(op)s(ened)f(with)f
  807. Fj(bzWriteOpen)542 3505 y(BZ_OK)663 3609 y Fl(otherwise)150
  808. 3766 y(Allo)m(w)m(able)h(next)g(actions:)572 3917 y Fj(bzReadClose)150
  809. 4158 y Ff(3.4.4)63 b Fe(bzReadClose)533 4345 y Fj(void)47
  810. b(bzReadClose)e(()i(int)g(*bzerror,)e(BZFILE)h(*b)h();)150
  811. 4502 y Fl(Releases)26 b(all)f(memory)g(p)s(ertaining)e(to)k(the)e
  812. (compressed)h(14le)e Fj(b)p Fl(.)39 b Fj(bzReadClose)23
  813. b Fl(do)s(es)i(not)h(call)f Fj(fclose)150 4611 y Fl(on)33
  814. b(the)f(underlying)e(14le)i(handle,)g(so)h(y)m(ou)g(should)d(do)j
  815. (that)g(y)m(ourself)f(if)f(appropriate.)47 b Fj(bzReadClose)150
  816. 4721 y Fl(should)28 b(b)s(e)i(called)g(to)h(clean)f(up)f(after)i(all)f
  817. (error)g(situations.)150 4878 y(P)m(ossible)f(assignmen)m(ts)h(to)h
  818. Fj(bzerror)p Fl(:)572 5029 y Fj(BZ_SEQUENCE_ERROR)663
  819. 5132 y Fl(if)e Fj(b)h Fl(w)m(as)h(op)s(ened)e(with)h
  820. Fj(bzOpenWrite)572 5236 y(BZ_OK)663 5340 y Fl(otherwise)p
  821. eop
  822. %%Page: 24 25
  823. 24 24 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  824. b(with)g Fj(libbzip2)1881 b Fl(24)150 366 y(Allo)m(w)m(able)30
  825. b(next)g(actions:)572 518 y(none)150 766 y Ff(3.4.5)63
  826. b Fe(bzWriteOpen)533 953 y Fj(BZFILE)46 b(*bzWriteOpen)f(()i(int)g
  827. (*bzerror,)e(FILE)i(*f,)1583 1057 y(int)g(blockSize100k,)d(int)j
  828. (verbosity,)1583 1160 y(int)g(workFactor)e();)150 1317
  829. y Fl(Prepare)33 b(to)g(write)f(compressed)h(data)h(to)f(14le)f
  830. (handle)g Fj(f)p Fl(.)47 b Fj(f)33 b Fl(should)e(refer)i(to)g(a)g
  831. (14le)f(whic)m(h)g(has)h(b)s(een)150 1427 y(op)s(ened)d(for)g
  832. (writing,)e(and)i(for)g(whic)m(h)f(the)i(error)f(indicator)f(()p
  833. Fj(ferror(f))p Fl()is)f(not)i(set.)150 1584 y(F)-8
  834. b(or)31 b(the)g(meaning)e(of)i(parameters)g Fj(blockSize100k)p
  835. Fl(,)c Fj(verbosity)g Fl(and)j Fj(workFactor)p Fl(,)e(see)150
  836. 1693 y Fj(bzCompressInit)p Fl(.)150 1850 y(All)d(required)f(memory)i
  837. (is)f(allo)s(cated)i(at)g(this)e(stage,)j(so)f(if)e(the)h(call)g
  838. (completes)g(successfully)-8 b(,)26 b Fj(BZ_MEM_)150
  839. 1960 y(ERROR)j Fl(cannot)i(b)s(e)f(signalled)e(b)m(y)i(a)h(subsequen)m
  840. (t)f(call)f(to)i Fj(bzWrite)p Fl(.)150 2117 y(P)m(ossible)e(assignmen)m
  841. (ts)h(to)h Fj(bzerror)p Fl(:)572 2268 y Fj(BZ_PARAM_ERROR)663
  842. 2371 y Fl(if)e Fj(f)h Fl(is)g Fj(NULL)663 2475 y Fl(or)g
  843. Fj(blockSize100k)44 b(<)k(1)30 b Fl(or)g Fj(blockSize100k)44
  844. b(>)k(9)572 2579 y(BZ_IO_ERROR)663 2683 y Fl(if)29 b
  845. Fj(ferror(f))f Fl(is)h(nonzero)572 2786 y Fj(BZ_MEM_ERROR)663
  846. 2890 y Fl(if)g(insu16cien)m(t)g(memory)h(is)f(a)m(v)-5
  847. b(ailable)572 2994 y Fj(BZ_OK)663 3098 y Fl(otherwise)150
  848. 3255 y(P)m(ossible)29 b(return)h(v)-5 b(alues:)572 3406
  849. y(P)m(oin)m(ter)31 b(to)g(an)f(abstract)h Fj(BZFILE)663
  850. 3509 y Fl(if)e Fj(bzerror)f Fl(is)i Fj(BZ_OK)572 3613
  851. y(NULL)663 3717 y Fl(otherwise)150 3874 y(Allo)m(w)m(able)g(next)g
  852. (actions:)572 4025 y Fj(bzWrite)663 4129 y Fl(if)f Fj(bzerror)f
  853. Fl(is)i Fj(BZ_OK)663 4232 y Fl((y)m(ou)h(could)e(go)i(directly)e(to)j
  854. Fj(bzWriteClose)p Fl(,)27 b(but)j(this)f(w)m(ould)g(b)s(e)h(prett)m(y)h
  855. (p)s(oin)m(tless))572 4336 y Fj(bzWriteClose)663 4440
  856. y Fl(otherwise)150 4689 y Ff(3.4.6)63 b Fe(bzWrite)533
  857. 4875 y Fj(void)47 b(bzWrite)f(()h(int)g(*bzerror,)e(BZFILE)h(*b,)h
  858. (void)g(*buf,)f(int)h(len)g();)150 5032 y Fl(Absorbs)26
  859. b Fj(len)g Fl(b)m(ytes)i(from)e(the)i(bu13er)e Fj(buf)p
  860. Fl(,)h(ev)m(en)m(tually)g(to)h(b)s(e)e(compressed)h(and)f(written)g(to)
  861. i(the)g(14le.)150 5189 y(P)m(ossible)h(assignmen)m(ts)h(to)h
  862. Fj(bzerror)p Fl(:)572 5340 y Fj(BZ_PARAM_ERROR)p eop
  863. %%Page: 25 26
  864. 25 25 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  865. b(with)g Fj(libbzip2)1881 b Fl(25)663 366 y(if)29 b Fj(b)h
  866. Fl(is)g Fj(NULL)f Fl(or)h Fj(buf)g Fl(is)f Fj(NULL)g
  867. Fl(or)i Fj(len)46 b(<)i(0)572 470 y(BZ_SEQUENCE_ERROR)663
  868. 574 y Fl(if)29 b(b)h(w)m(as)h(op)s(ened)e(with)g Fj(bzReadOpen)572
  869. 678 y(BZ_IO_ERROR)663 782 y Fl(if)g(there)i(is)e(an)h(error)g(writing)f
  870. (the)h(compressed)g(14le.)572 885 y Fj(BZ_OK)663 989
  871. y Fl(otherwise)150 1253 y Ff(3.4.7)63 b Fe(bzWriteClose)533
  872. 1440 y Fj(int)47 b(bzWriteClose)e(()i(int)g(*bzerror,)e(BZFILE*)h(f,)
  873. 1440 1544 y(int)h(abandon,)1440 1648 y(unsigned)f(int*)g(nbytes_in,)
  874. 1440 1751 y(unsigned)g(int*)g(nbytes_out)f();)150 1908
  875. y Fl(Compresses)37 b(and)g(15ushes)f(to)j(the)f(compressed)f(14le)g
  876. (all)f(data)j(so)e(far)h(supplied)c(b)m(y)k Fj(bzWrite)p
  877. Fl(.)60 b(The)150 2018 y(logical)34 b(end-of-stream)i(mark)m(ers)f(are)
  878. g(also)g(written,)h(so)f(subsequen)m(t)f(calls)g(to)i
  879. Fj(bzWrite)d Fl(are)i(illegal.)150 2128 y(All)42 b(memory)h(asso)s
  880. (ciated)h(with)e(the)i(compressed)f(14le)g Fj(b)g Fl(is)f(released.)
  881. 80 b Fj(fflush)41 b Fl(is)i(called)f(on)i(the)150 2237
  882. y(compressed)30 b(14le,)g(but)f(it)h(is)g(not)g Fj(fclose)p
  883. Fl('d.)150 2394 y(If)22 b Fj(bzWriteClose)e Fl(is)i(called)g(to)h
  884. (clean)g(up)f(after)h(an)g(error,)h(the)f(only)f(action)h(is)f(to)h
  885. (release)g(the)g(memory)-8 b(.)150 2504 y(The)23 b(library)e(records)i
  886. (the)h(error)f(co)s(des)g(issued)f(b)m(y)h(previous)f(calls,)i(so)g
  887. (this)e(situation)g(will)f(b)s(e)i(detected)150 2613
  888. y(automatically)-8 b(.)44 b(There)31 b(is)g(no)g(attempt)i(to)f
  889. (complete)g(the)g(compression)e(op)s(eration,)h(nor)g(to)i
  890. Fj(fflush)150 2723 y Fl(the)h(compressed)g(14le.)51
  891. b(Y)-8 b(ou)34 b(can)h(force)f(this)f(b)s(eha)m(viour)g(to)i(happ)s(en)
  892. d(ev)m(en)j(in)e(the)h(case)h(of)f(no)g(error,)150 2832
  893. y(b)m(y)c(passing)f(a)i(nonzero)g(v)-5 b(alue)30 b(to)h
  894. Fj(abandon)p Fl(.)150 2989 y(If)j Fj(nbytes_in)d Fl(is)j(non-n)m(ull,)f
  895. Fj(*nbytes_in)e Fl(will)h(b)s(e)h(set)i(to)g(b)s(e)f(the)g(total)h(v)m
  896. (olume)f(of)g(uncompressed)150 3099 y(data)k(handled.)60
  897. b(Similarly)-8 b(,)35 b Fj(nbytes_out)g Fl(will)g(b)s(e)h(set)i(to)g
  898. (the)g(total)g(v)m(olume)f(of)g(compressed)g(data)150
  899. 3208 y(written.)150 3365 y(P)m(ossible)29 b(assignmen)m(ts)h(to)h
  900. Fj(bzerror)p Fl(:)572 3516 y Fj(BZ_SEQUENCE_ERROR)663
  901. 3620 y Fl(if)e Fj(b)h Fl(w)m(as)h(op)s(ened)e(with)h
  902. Fj(bzReadOpen)572 3724 y(BZ_IO_ERROR)663 3827 y Fl(if)f(there)i(is)e
  903. (an)h(error)g(writing)f(the)h(compressed)g(14le)572
  904. 3931 y Fj(BZ_OK)663 4035 y Fl(otherwise)150 4299 y Ff(3.4.8)63
  905. b(Handling)41 b(em)m(b)s(edded)g(compressed)h(data)e(streams)150
  906. 4492 y Fl(The)i(high-lev)m(el)g(library)f(facilitates)h(use)h(of)g
  907. Fj(bzip2)e Fl(data)j(streams)f(whic)m(h)f(form)g(some)i(part)e(of)i(a)
  908. 150 4601 y(surrounding,)27 b(larger)j(data)h(stream.)225
  909. 4758 y Fi(17)60 b Fl(F)-8 b(or)22 b(writing,)f(the)g(library)e(tak)m
  910. (es)k(an)e(op)s(en)f(14le)g(handle,)i(writes)e(compressed)h(data)h
  911. (to)g(it,)g Fj(fflush)p Fl(es)330 4868 y(it)34 b(but)f(do)s(es)h(not)h
  912. Fj(fclose)d Fl(it.)52 b(The)34 b(calling)f(application)g(can)h(write)g
  913. (its)f(o)m(wn)i(data)g(b)s(efore)f(and)330 4977 y(after)d(the)f
  914. (compressed)h(data)g(stream,)g(using)d(that)j(same)g(14le)f(handle.)
  915. 225 5121 y Fi(17)60 b Fl(Reading)34 b(is)f(more)i(complex,)g(and)f
  916. (the)h(facilities)d(are)j(not)g(as)g(general)f(as)h(they)f(could)g(b)s
  917. (e)g(since)330 5230 y(generalit)m(y)27 b(is)f(hard)f(to)j(reconcile)e
  918. (with)g(e16ciency)-8 b(.)40 b Fj(bzRead)25 b Fl(reads)i(from)f(the)h
  919. (compressed)f(14le)g(in)330 5340 y(blo)s(c)m(ks)f(of)h(size)g
  920. Fj(BZ_MAX_UNUSED)c Fl(b)m(ytes,)27 b(and)e(in)g(doing)f(so)i(probably)e
  921. (will)f(o)m(v)m(ersho)s(ot)28 b(the)d(logical)p eop
  922. %%Page: 26 27
  923. 26 26 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  924. b(with)g Fj(libbzip2)1881 b Fl(26)330 366 y(end)37 b(of)h(compressed)f
  925. (stream.)63 b(T)-8 b(o)39 b(reco)m(v)m(er)g(this)e(data)h(once)h
  926. (decompression)d(has)i(ended,)h(call)330 476 y Fj(bzReadGetUnused)23
  927. b Fl(after)k(the)g(last)g(call)g(of)g Fj(bzRead)e Fl((the)j(one)f
  928. (returning)e Fj(BZ_STREAM_END)p Fl())f(but)330 586 y(b)s(efore)30
  929. b(calling)f Fj(bzReadClose)p Fl(.)150 784 y(This)36 b(mec)m(hanism)g
  930. (mak)m(es)i(it)f(easy)h(to)g(decompress)f(m)m(ultiple)e
  931. Fj(bzip2)h Fl(streams)i(placed)f(end-to-end.)150 893
  932. y(As)j(the)h(end)f(of)h(one)f(stream,)k(when)c Fj(bzRead)e
  933. Fl(returns)i Fj(BZ_STREAM_END)p Fl(,)f(call)h Fj(bzReadGetUnused)150
  934. 1003 y Fl(to)i(collect)f(the)h(un)m(used)d(data)j((cop)m(y)g(it)f(in)m
  935. (to)g(y)m(our)g(o)m(wn)g(bu13er)f(somewhere).)73 b(That)41
  936. b(data)h(forms)150 1112 y(the)c(start)h(of)g(the)f(next)g(compressed)g
  937. (stream.)65 b(T)-8 b(o)39 b(start)f(uncompressing)f(that)h(next)h
  938. (stream,)i(call)150 1222 y Fj(bzReadOpen)30 b Fl(again,)j(feeding)f(in)
  939. f(the)i(un)m(used)e(data)i(via)f(the)h Fj(unused)p Fl(/)p
  940. Fj(nUnused)c Fl(parameters.)48 b(Keep)150 1332 y(doing)26
  941. b(this)g(un)m(til)f Fj(BZ_STREAM_END)f Fl(return)i(coincides)g(with)g
  942. (the)h(ph)m(ysical)f(end)g(of)h(14le)f(()p Fj(feof(f))p
  943. Fl().)39 b(In)150 1441 y(this)29 b(situation)h Fj(bzReadGetUnused)c
  944. Fl(will)h(of)k(course)g(return)e(no)h(data.)150 1598
  945. y(This)c(should)f(giv)m(e)j(some)g(feel)f(for)g(ho)m(w)h(the)g
  946. (high-lev)m(el)e(in)m(terface)i(can)f(b)s(e)g(used.)39
  947. b(If)27 b(y)m(ou)h(require)e(extra)150 1708 y(15exibilit)m(y)-8
  948. b(,)28 b(y)m(ou'll)i(ha)m(v)m(e)h(to)g(bite)f(the)h(bullet)d(and)i(get)
  949. i(to)f(grips)e(with)g(the)h(lo)m(w-lev)m(el)h(in)m(terface.)150
  950. 1987 y Ff(3.4.9)63 b(Standard)40 b(14le-reading/writing)j(co)s(de)150
  951. 2179 y Fl(Here's)31 b(ho)m(w)f(y)m(ou'd)h(write)e(data)j(to)f(a)f
  952. (compressed)g(14le:)390 2538 y Fj(FILE*)142 b(f;)390
  953. 2642 y(BZFILE*)46 b(b;)390 2746 y(int)238 b(nBuf;)390
  954. 2849 y(char)190 b(buf[)46 b(/*)i(whatever)d(size)i(you)g(like)f(*/)i
  955. (];)390 2953 y(int)238 b(bzerror;)390 3057 y(int)g(nWritten;)390
  956. 3264 y(f)47 b(=)h(fopen)e(()i("myfile.bz2",)c("w")j();)390
  957. 3368 y(if)g((!f))g({)533 3472 y(/*)g(handle)f(error)h(*/)390
  958. 3576 y(})390 3680 y(b)g(=)h(bzWriteOpen)d(()i(&bzerror,)e(f,)j(9)f
  959. ();)390 3783 y(if)g((bzerror)f(!=)h(BZ_OK))f({)533
  960. 3887 y(bzWriteClose)f(()i(b)h();)533 3991 y(/*)f(handle)f(error)h(*/)
  961. 390 4095 y(})390 4302 y(while)f(()i(/*)f(condition)e(*/)i())h({)533
  962. 4406 y(/*)f(get)g(data)g(to)g(write)f(into)h(buf,)g(and)g(set)g(nBuf)f
  963. (appropriately)e(*/)533 4510 y(nWritten)i(=)h(bzWrite)f(()h(&bzerror,)
  964. f(b,)h(buf,)g(nBuf)f();)533 4614 y(if)h((bzerror)f(==)h
  965. (BZ_IO_ERROR))e({)676 4717 y(bzWriteClose)g(()i(&bzerror,)f(b)h();)
  966. 676 4821 y(/*)h(handle)e(error)g(*/)533 4925 y(})390
  967. 5029 y(})390 5236 y(bzWriteClose)e(()k(&bzerror,)d(b)j();)390
  968. 5340 y(if)f((bzerror)f(==)h(BZ_IO_ERROR))d({)p eop
  969. %%Page: 27 28
  970. 27 27 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  971. b(with)g Fj(libbzip2)1881 b Fl(27)533 366 y Fj(/*)47
  972. b(handle)f(error)h(*/)390 470 y(})150 627 y Fl(And)29
  973. b(to)j(read)e(from)g(a)h(compressed)f(14le:)390 778
  974. y Fj(FILE*)142 b(f;)390 882 y(BZFILE*)46 b(b;)390 986
  975. y(int)238 b(nBuf;)390 1089 y(char)190 b(buf[)46 b(/*)i(whatever)d(size)
  976. i(you)g(like)f(*/)i(];)390 1193 y(int)238 b(bzerror;)390
  977. 1297 y(int)g(nWritten;)390 1505 y(f)47 b(=)h(fopen)e(()i
  978. ("myfile.bz2",)c("r")j();)390 1608 y(if)g((!f))g({)533
  979. 1712 y(/*)g(handle)f(error)h(*/)390 1816 y(})390 1920
  980. y(b)g(=)h(bzReadOpen)d(()i(&bzerror,)f(f,)h(0,)g(NULL,)f(0)i();)390
  981. 2023 y(if)f((bzerror)f(!=)h(BZ_OK))f({)533 2127 y(bzReadClose)f(()i
  982. (&bzerror,)f(b)h();)533 2231 y(/*)g(handle)f(error)h(*/)390
  983. 2335 y(})390 2542 y(bzerror)f(=)h(BZ_OK;)390 2646 y(while)f((bzerror)g
  984. (==)h(BZ_OK)f(&&)i(/*)f(arbitrary)e(other)h(conditions)f(*/))i({)533
  985. 2750 y(nBuf)g(=)g(bzRead)f(()i(&bzerror,)d(b,)i(buf,)g(/*)g(size)g(of)
  986. g(buf)g(*/)g();)533 2854 y(if)g((bzerror)f(==)h(BZ_OK))f({)676
  987. 2957 y(/*)i(do)f(something)e(with)i(buf[0)f(..)h(nBuf-1])f(*/)533
  988. 3061 y(})390 3165 y(})390 3269 y(if)h((bzerror)f(!=)h(BZ_STREAM_END))
  989. d({)533 3373 y(bzReadClose)h(()i(&bzerror,)f(b)h();)533
  990. 3476 y(/*)g(handle)f(error)h(*/)390 3580 y(})g(else)g({)533
  991. 3684 y(bzReadClose)e(()i(&bzerror)f();)390 3788 y(})150
  992. 4176 y Fk(3.5)68 b(Utilit)l(y)47 b(functions)150 4531
  993. y Ff(3.5.1)63 b Fe(bzBuffToBuffCompress)533 4717 y Fj(int)47
  994. b(bzBuffToBuffCompress()42 b(char*)428 b(dest,)1774
  995. 4821 y(unsigned)46 b(int*)g(destLen,)1774 4925 y(char*)428
  996. b(source,)1774 5029 y(unsigned)46 b(int)94 b(sourceLen,)1774
  997. 5132 y(int)524 b(blockSize100k,)1774 5236 y(int)g(verbosity,)1774
  998. 5340 y(int)g(workFactor)45 b();)p eop
  999. %%Page: 28 29
  1000. 28 28 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  1001. b(with)g Fj(libbzip2)1881 b Fl(28)150 366 y(A)m(ttempts)33
  1002. b(to)g(compress)f(the)g(data)h(in)e Fj(source[0)d(..)i(sourceLen-1])e
  1003. Fl(in)m(to)k(the)h(destination)e(bu13er,)150 476 y
  1004. Fj(dest[0)e(..)g(*destLen-1])p Fl(.)37 b(If)26 b(the)g(destination)g
  1005. (bu13er)f(is)h(big)f(enough,)j Fj(*destLen)c Fl(is)h(set)i(to)g(the)g
  1006. (size)150 586 y(of)i(the)f(compressed)h(data,)g(and)f
  1007. Fj(BZ_OK)f Fl(is)h(returned.)39 b(If)28 b(the)h(compressed)f(data)h(w)m
  1008. (on't)g(14t,)g Fj(*destLen)150 695 y Fl(is)g(unc)m(hanged,)i(and)e
  1009. Fj(BZ_OUTBUFF_FULL)e Fl(is)i(returned.)150 852 y(Compression)22
  1010. b(in)g(this)h(manner)g(is)g(a)h(one-shot)g(ev)m(en)m(t,)j(done)c(with)g
  1011. (a)h(single)e(call)h(to)i(this)d(function.)37 b(The)150
  1012. 962 y(resulting)25 b(compressed)i(data)i(is)d(a)i(complete)f
  1013. Fj(bzip2)f Fl(format)i(data)g(stream.)40 b(There)27 b(is)f(no)i(mec)m
  1014. (hanism)150 1071 y(for)23 b(making)g(additional)e(calls)i(to)h(pro)m
  1015. (vide)f(extra)h(input)e(data.)39 b(If)23 b(y)m(ou)h(w)m(an)m(t)g(that)g
  1016. (kind)e(of)h(mec)m(hanism,)150 1181 y(use)30 b(the)h(lo)m(w-lev)m(el)f
  1017. (in)m(terface.)150 1338 y(F)-8 b(or)31 b(the)g(meaning)e(of)i
  1018. (parameters)g Fj(blockSize100k)p Fl(,)c Fj(verbosity)g
  1019. Fl(and)j Fj(workFactor)p Fl(,)150 1447 y(see)h Fj(bzCompressInit)p
  1020. Fl(.)150 1604 y(T)-8 b(o)27 b(guaran)m(tee)h(that)e(the)h(compressed)f
  1021. (data)h(will)d(14t)i(in)f(its)g(bu13er,)i(allo)s(cate)f(an)g
  1022. (output)g(bu13er)g(of)g(size)150 1714 y(145)31 b(larger)f(than)g
  1023. (the)g(uncompressed)f(data,)j(plus)c(six)h(h)m(undred)g(extra)i(b)m
  1024. (ytes.)150 1871 y Fj(bzBuffToBuffDecompress)25 b Fl(will)k(not)i(write)
  1025. g(data)h(at)g(or)f(b)s(ey)m(ond)f Fj(dest[*destLen])p
  1026. Fl(,)e(ev)m(en)k(in)e(case)150 1980 y(of)h(bu13er)e(o)m(v)m(er15o)m
  1027. (w.)150 2137 y(P)m(ossible)g(return)h(v)-5 b(alues:)572
  1028. 2288 y Fj(BZ_PARAM_ERROR)663 2392 y Fl(if)29 b Fj(dest)g
  1029. Fl(is)h Fj(NULL)f Fl(or)h Fj(destLen)f Fl(is)g Fj(NULL)663
  1030. 2496 y Fl(or)h Fj(blockSize100k)44 b(<)k(1)30 b Fl(or)g
  1031. Fj(blockSize100k)44 b(>)k(9)663 2599 y Fl(or)30 b Fj(verbosity)45
  1032. b(<)j(0)30 b Fl(or)g Fj(verbosity)45 b(>)j(4)663 2703
  1033. y Fl(or)30 b Fj(workFactor)45 b(<)j(0)30 b Fl(or)g Fj(workFactor)45
  1034. b(>)i(250)572 2807 y(BZ_MEM_ERROR)663 2911 y Fl(if)29
  1035. b(insu16cien)m(t)g(memory)h(is)f(a)m(v)-5 b(ailable)572
  1036. 3014 y Fj(BZ_OUTBUFF_FULL)663 3118 y Fl(if)29 b(the)i(size)f(of)g(the)h
  1037. (compressed)f(data)h(exceeds)g Fj(*destLen)572 3222 y(BZ_OK)663
  1038. 3326 y Fl(otherwise)150 3725 y Ff(3.5.2)63 b Fe(bzBuffToBuffDecompress)
  1039. 533 3912 y Fj(int)47 b(bzBuffToBuffDecompress)42 b(()47
  1040. b(char*)428 b(dest,)1917 4016 y(unsigned)46 b(int*)g(destLen,)1917
  1041. 4120 y(char*)428 b(source,)1917 4224 y(unsigned)46 b(int)94
  1042. b(sourceLen,)1917 4327 y(int)524 b(small,)1917 4431 y(int)g(verbosity)
  1043. 46 b();)150 4588 y Fl(A)m(ttempts)24 b(to)g(decompress)f(the)g(data)g
  1044. (in)f Fj(source[0)28 b(..)i(sourceLen-1])20 b Fl(in)m(to)j(the)g
  1045. (destination)f(bu13er,)150 4698 y Fj(dest[0)29 b(..)g(*destLen-1])p
  1046. Fl(.)37 b(If)26 b(the)g(destination)g(bu13er)f(is)h(big)f(enough,)j
  1047. Fj(*destLen)c Fl(is)h(set)i(to)g(the)g(size)150 4807
  1048. y(of)21 b(the)g(uncompressed)e(data,)24 b(and)c Fj(BZ_OK)f
  1049. Fl(is)h(returned.)36 b(If)20 b(the)h(compressed)g(data)g(w)m(on't)h
  1050. (14t,)g Fj(*destLen)150 4917 y Fl(is)29 b(unc)m(hanged,)i(and)e
  1051. Fj(BZ_OUTBUFF_FULL)e Fl(is)i(returned.)150 5074 y Fj(source)19
  1052. b Fl(is)g(assumed)h(to)i(hold)d(a)i(complete)g Fj(bzip2)e
  1053. Fl(format)i(data)g(stream.)38 b Fj(bzBuffToBuffDecompress)150
  1054. 5183 y Fl(tries)30 b(to)h(decompress)f(the)h(en)m(tiret)m(y)g(of)f(the)
  1055. h(stream)f(in)m(to)h(the)f(output)g(bu13er.)150 5340
  1056. y(F)-8 b(or)31 b(the)g(meaning)e(of)i(parameters)g Fj(small)e
  1057. Fl(and)g Fj(verbosity)p Fl(,)f(see)j Fj(bzDecompressInit)p
  1058. Fl(.)p eop
  1059. %%Page: 29 30
  1060. 29 29 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  1061. b(with)g Fj(libbzip2)1881 b Fl(29)150 366 y(Because)34
  1062. b(the)f(compression)e(ratio)i(of)g(the)g(compressed)f(data)h(cannot)g
  1063. (b)s(e)f(kno)m(wn)g(in)g(adv)-5 b(ance,)34 b(there)150
  1064. 476 y(is)d(no)h(easy)g(w)m(a)m(y)h(to)f(guaran)m(tee)i(that)e(the)g
  1065. (output)f(bu13er)g(will)e(b)s(e)i(big)g(enough.)45
  1066. b(Y)-8 b(ou)32 b(ma)m(y)h(of)f(course)150 586 y(mak)m(e)k(arrangemen)m
  1067. (ts)f(in)e(y)m(our)i(co)s(de)g(to)g(record)g(the)g(size)f(of)h(the)g
  1068. (uncompressed)f(data,)i(but)e(suc)m(h)h(a)150 695 y(mec)m(hanism)30
  1069. b(is)f(b)s(ey)m(ond)h(the)g(scop)s(e)h(of)f(this)g(library)-8
  1070. b(.)150 852 y Fj(bzBuffToBuffDecompress)25 b Fl(will)k(not)i(write)g
  1071. (data)h(at)g(or)f(b)s(ey)m(ond)f Fj(dest[*destLen])p
  1072. Fl(,)e(ev)m(en)k(in)e(case)150 962 y(of)h(bu13er)e(o)m(v)m(er15o)m
  1073. (w.)150 1119 y(P)m(ossible)g(return)h(v)-5 b(alues:)572
  1074. 1270 y Fj(BZ_PARAM_ERROR)663 1373 y Fl(if)29 b Fj(dest)g
  1075. Fl(is)h Fj(NULL)f Fl(or)h Fj(destLen)f Fl(is)g Fj(NULL)663
  1076. 1477 y Fl(or)h Fj(small)46 b(!=)i(0)f(&&)g(small)g(!=)g(1)663
  1077. 1581 y Fl(or)30 b Fj(verbosity)45 b(<)j(0)30 b Fl(or)g
  1078. Fj(verbosity)45 b(>)j(4)572 1685 y(BZ_MEM_ERROR)663 1788
  1079. y Fl(if)29 b(insu16cien)m(t)g(memory)h(is)f(a)m(v)-5
  1080. b(ailable)572 1892 y Fj(BZ_OUTBUFF_FULL)663 1996 y Fl(if)29
  1081. b(the)i(size)f(of)g(the)h(compressed)f(data)h(exceeds)g
  1082. Fj(*destLen)572 2100 y(BZ_DATA_ERROR)663 2204 y Fl(if)e(a)i(data)g(in)m
  1083. (tegrit)m(y)f(error)g(w)m(as)h(detected)h(in)d(the)h(compressed)g(data)
  1084. 572 2307 y Fj(BZ_DATA_ERROR_MAGIC)663 2411 y Fl(if)f(the)i(compressed)f
  1085. (data)h(do)s(esn't)f(b)s(egin)f(with)g(the)i(righ)m(t)e(magic)i(b)m
  1086. (ytes)572 2515 y Fj(BZ_UNEXPECTED_EOF)663 2619 y Fl(if)e(the)i
  1087. (compressed)f(data)h(ends)e(unexp)s(ectedly)572 2722
  1088. y Fj(BZ_OK)663 2826 y Fl(otherwise)150 3141 y Fk(3.6)68
  1089. b(Using)46 b(the)f(library)g(in)g(a)g Fd(stdio)p Fk(-free)f(en)l
  1090. (vironmen)l(t)150 3447 y Ff(3.6.1)63 b(Getting)40 b(rid)h(of)g
  1091. Fe(stdio)150 3640 y Fl(In)i(a)g(deeply)g(em)m(b)s(edded)f(application,)
  1092. j(y)m(ou)f(migh)m(t)f(w)m(an)m(t)h(to)g(use)f(just)g(the)h
  1093. (memory-to-memory)150 3749 y(functions.)39 b(Y)-8 b(ou)30
  1094. b(can)f(do)g(this)g(con)m(v)m(enien)m(tly)g(b)m(y)g(compiling)e(the)j
  1095. (library)d(with)h(prepro)s(cessor)g(sym)m(b)s(ol)150
  1096. 3859 y Fj(BZ_NO_STDIO)35 b Fl(de14ned.)63 b(Doing)39
  1097. b(this)e(giv)m(es)h(y)m(ou)h(a)f(library)e(con)m(taining)i(only)f(the)i
  1098. (follo)m(wing)e(eigh)m(t)150 3968 y(functions:)150 4125
  1099. y Fj(bzCompressInit)p Fl(,)27 b Fj(bzCompress)p Fl(,)h
  1100. Fj(bzCompressEnd)150 4235 y(bzDecompressInit)p Fl(,)e
  1101. Fj(bzDecompress)p Fl(,)h Fj(bzDecompressEnd)150 4344
  1102. y(bzBuffToBuffCompress)p Fl(,)e Fj(bzBuffToBuffDecompress)150
  1103. 4501 y Fl(When)30 b(compiled)f(lik)m(e)h(this,)f(all)g(functions)g
  1104. (will)f(ignore)i Fj(verbosity)e Fl(settings.)150 4771
  1105. y Ff(3.6.2)63 b(Critical)40 b(error)h(handling)150 4964
  1106. y Fj(libbzip2)20 b Fl(con)m(tains)j(a)g(n)m(um)m(b)s(er)f(of)g(in)m
  1107. (ternal)g(assertion)g(c)m(hec)m(ks)i(whic)m(h)d(should,)i(needless)f
  1108. (to)h(sa)m(y)-8 b(,)26 b(nev)m(er)150 5074 y(b)s(e)g(activ)-5
  1109. b(ated.)40 b(Nev)m(ertheless,)28 b(if)d(an)i(assertion)f(should)e
  1110. (fail,)i(b)s(eha)m(viour)f(dep)s(ends)f(on)j(whether)e(or)i(not)150
  1111. 5183 y(the)k(library)d(w)m(as)i(compiled)f(with)g Fj(BZ_NO_STDIO)e
  1112. Fl(set.)150 5340 y(F)-8 b(or)31 b(a)g(normal)e(compile,)h(an)g
  1113. (assertion)g(failure)f(yields)f(the)j(message)p eop
  1114. %%Page: 30 31
  1115. 30 30 bop 150 -116 a Fl(Chapter)30 b(3:)41 b(Programming)29
  1116. b(with)g Fj(libbzip2)1881 b Fl(30)533 366 y Fj(bzip2/libbzip2,)44
  1117. b(v0.9.0:)i(internal)f(error)i(number)f(N.)533 470 y(This)h(is)g(a)g
  1118. (bug)g(in)h(bzip2/libbzip2,)43 b(v0.9.0.)94 b(Please)46
  1119. b(report)533 574 y(it)h(to)h(me)f(at:)g(jseward@acm.org.)91
  1120. b(If)47 b(this)g(happened)e(when)533 678 y(you)i(were)g(using)f(some)h
  1121. (program)f(which)g(uses)h(libbzip2)e(as)i(a)533 782 y(component,)e(you)
  1122. i(should)f(also)h(report)f(this)h(bug)f(to)i(the)f(author(s))533
  1123. 885 y(of)g(that)g(program.)93 b(Please)46 b(make)h(an)g(effort)f(to)h
  1124. (report)g(this)f(bug;)533 989 y(timely)g(and)h(accurate)f(bug)h
  1125. (reports)e(eventually)g(lead)i(to)g(higher)533 1093 y(quality)f
  1126. (software.)93 b(Thx.)h(Julian)46 b(Seward,)g(27)h(June)g(1998.)150
  1127. 1250 y Fl(where)30 b Fj(N)g Fl(is)f(some)i(error)f(co)s(de)h(n)m(um)m
  1128. (b)s(er.)39 b Fj(exit(3))28 b Fl(is)i(then)g(called.)150
  1129. 1407 y(F)-8 b(or)31 b(a)g Fj(stdio)p Fl(-free)e(library)-8
  1130. b(,)29 b(assertion)h(failures)e(result)i(in)f(a)i(call)e(to)i(a)g
  1131. (function)e(declared)h(as:)533 1558 y Fj(extern)46 b(void)h
  1132. (bz_internal_error)c(()k(int)g(errcode)f();)150 1714
  1133. y Fl(The)30 b(relev)-5 b(an)m(t)31 b(co)s(de)f(is)g(passed)f(as)i(a)g
  1134. (parameter.)41 b(Y)-8 b(ou)31 b(should)d(supply)g(suc)m(h)i(a)h
  1135. (function.)150 1871 y(In)g(either)g(case,)j(once)e(an)g(assertion)g
  1136. (failure)e(has)h(o)s(ccurred,)h(an)m(y)g Fj(bz_stream)e
  1137. Fl(records)h(in)m(v)m(olv)m(ed)h(can)150 1981 y(b)s(e)e(regarded)g(as)h
  1138. (in)m(v)-5 b(alid.)38 b(Y)-8 b(ou)31 b(should)d(not)j(attempt)g(to)g
  1139. (resume)f(normal)g(op)s(eration)f(with)g(them.)150 2138
  1140. y(Y)-8 b(ou)22 b(ma)m(y)-8 b(,)25 b(of)d(course,)h(c)m(hange)g
  1141. (critical)e(error)g(handling)e(to)j(suit)f(y)m(our)g(needs.)38
  1142. b(As)21 b(I)h(said)e(ab)s(o)m(v)m(e,)25 b(critical)150
  1143. 2247 y(errors)30 b(indicate)g(bugs)g(in)g(the)h(library)d(and)i(should)
  1144. f(not)i(o)s(ccur.)42 b(All)29 b Fj(")p Fl(normal)p Fj(")h
  1145. Fl(error)g(situations)g(are)150 2357 y(indicated)f(via)h(error)g
  1146. (return)f(co)s(des)i(from)f(functions,)f(and)g(can)i(b)s(e)f(reco)m(v)m
  1147. (ered)i(from.)150 2637 y Fk(3.7)68 b(Making)45 b(a)g(Windo)l(ws)h(DLL)
  1148. 150 2829 y Fl(Ev)m(erything)30 b(related)g(to)h(Windo)m(ws)f(has)g(b)s
  1149. (een)f(con)m(tributed)h(b)m(y)g(Y)-8 b(oshiok)j(a)31
  1150. b(Tsuneo)150 2939 y(()p Fj(QWF00133@niftyserve.or.jp)46
  1151. b Fl(/)52 b Fj(tsuneo-y@is.aist-nara.ac.j)o(p)p Fl(),)g(so)h(y)m(ou)f
  1152. (should)f(send)150 3048 y(y)m(our)30 b(queries)g(to)h(him)e((but)h(p)s
  1153. (erhaps)e(Cc:)41 b(me,)31 b Fj(jseward@acm.org)p Fl().)150
  1154. 3205 y(My)43 b(v)-5 b(ague)44 b(understanding)d(of)i(what)g(to)h(do)f
  1155. (is:)65 b(using)41 b(Visual)h(C)p Fj(++)g Fl(5.0,)48
  1156. b(op)s(en)42 b(the)h(pro)5 b(ject)44 b(14le)150 3315
  1157. y Fj(libbz2.dsp)p Fl(,)28 b(and)i(build.)37 b(That's)31
  1158. b(all.)150 3472 y(If)41 b(y)m(ou)g(can't)h(op)s(en)e(the)h(pro)5
  1159. b(ject)42 b(14le)e(for)h(some)g(reason,)j(mak)m(e)e(a)g(new)e(one,)k
  1160. (naming)c(these)i(14les:)150 3581 y Fj(blocksort.c)p
  1161. Fl(,)28 b Fj(bzlib.c)p Fl(,)g Fj(compress.c)p Fl(,)g
  1162. Fj(crctable.c)p Fl(,)g Fj(decompress.c)p Fl(,)f Fj(huffman.c)p
  1163. Fl(,)150 3691 y Fj(randtable.c)f Fl(and)j Fj(libbz2.def)p
  1164. Fl(.)38 b(Y)-8 b(ou)29 b(migh)m(t)g(also)h(need)f(to)h(name)f(the)h
  1165. (header)f(14les)f Fj(bzlib.h)g Fl(and)150 3800 y Fj(bzlib_private.h)p
  1166. Fl(.)150 3957 y(If)i(y)m(ou)h(don't)f(use)g(V)m(C)p Fj(++)p
  1167. Fl(,)g(y)m(ou)h(ma)m(y)g(need)f(to)h(de14ne)f(the)h(propro)s(cessor)e
  1168. (sym)m(b)s(ol)g Fj(_WIN32)p Fl(.)150 4114 y(Finally)-8
  1169. b(,)28 b Fj(dlltest.c)e Fl(is)h(a)i(sample)f(program)g(using)g(the)g
  1170. (DLL.)h(It)g(has)f(a)h(pro)5 b(ject)29 b(14le,)g Fj(dlltest.dsp)p
  1171. Fl(.)150 4271 y(I)h(ha)m(v)m(en't)i(tried)d(an)m(y)i(of)g(this)e
  1172. (stu13)h(m)m(yself,)g(but)g(it)f(all)h(lo)s(oks)g(plausible.)p
  1173. eop
  1174. %%Page: 31 32
  1175. 31 31 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1176. b(31)150 366 y Fh(4)80 b(Miscellanea)150 594 y Fl(These)30
  1177. b(are)h(just)f(some)g(random)g(though)m(ts)h(of)f(mine.)40
  1178. b(Y)-8 b(our)30 b(mileage)h(ma)m(y)g(v)-5 b(ary)d(.)150
  1179. 860 y Fk(4.1)68 b(Limitations)47 b(of)e(the)g(compressed)g(14le)h
  1180. (format)150 1052 y Fj(bzip2-0.9.0)21 b Fl(uses)j(exactly)h(the)f(same)g
  1181. (14le)g(format)g(as)g(the)h(previous)d(v)m(ersion,)j
  1182. Fj(bzip2-0.1)p Fl(.)36 b(This)23 b(de-)150 1162 y(cision)j(w)m(as)i
  1183. (made)g(in)e(the)i(in)m(terests)g(of)g(stabilit)m(y)-8
  1184. b(.)39 b(Creating)27 b(y)m(et)i(another)f(incompatible)d(compressed)150
  1185. 1271 y(14le)k(format)i(w)m(ould)e(create)j(further)d(confusion)g(and)
  1186. h(disruption)d(for)j(users.)150 1428 y(Nev)m(ertheless,)h(this)e(is)g
  1187. (not)h(a)g(painless)e(decision.)39 b(Dev)m(elopmen)m(t)31
  1188. b(w)m(ork)f(since)f(the)h(release)h(of)f Fj(bzip2-)150
  1189. 1538 y(0.1)19 b Fl(in)g(August)i(1997)h(has)e(sho)m(wn)f(complexities)h
  1190. (in)f(the)h(14le)g(format)g(whic)m(h)f(slo)m(w)h(do)m(wn)g
  1191. (decompression)150 1647 y(and,)30 b(in)f(retrosp)s(ect,)i(are)g
  1192. (unnecessary)-8 b(.)40 b(These)31 b(are:)225 1804 y Fi(17)60
  1193. b Fl(The)20 b(run-length)g(enco)s(der,)i(whic)m(h)e(is)g(the)h(14rst)
  1194. f(of)h(the)g(compression)f(transformations,)i(is)e(en)m(tirely)330
  1195. 1914 y(irrelev)-5 b(an)m(t.)63 b(The)38 b(original)e(purp)s(ose)g(w)m
  1196. (as)j(to)g(protect)g(the)f(sorting)g(algorithm)f(from)g(the)i(v)m(ery)
  1197. 330 2023 y(w)m(orst)h(case)h(input:)58 b(a)41 b(string)e(of)h(rep)s
  1198. (eated)g(sym)m(b)s(ols.)68 b(But)40 b(algorithm)f(steps)h(Q6a)h(and)e
  1199. (Q6b)330 2133 y(in)30 b(the)i(original)e(Burro)m(ws-Wheeler)i(tec)m
  1200. (hnical)g(rep)s(ort)f((SR)m(C-124))i(sho)m(w)f(ho)m(w)g(rep)s(eats)g
  1201. (can)g(b)s(e)330 2243 y(handled)c(without)i(di16cult)m(y)f(in)g(blo)s
  1202. (c)m(k)h(sorting.)225 2370 y Fi(17)60 b Fl(The)30 b(randomisation)e
  1203. (mec)m(hanism)i(do)s(esn't)g(really)f(need)h(to)g(b)s(e)g(there.)41
  1204. b(Udi)29 b(Man)m(b)s(er)h(and)f(Gene)330 2479 y(My)m(ers)j(published)c
  1205. (a)33 b(su16x)e(arra)m(y)h(construction)f(algorithm)g(a)h(few)g(y)m
  1206. (ears)h(bac)m(k,)g(whic)m(h)d(can)j(b)s(e)330 2589 y(emplo)m(y)m(ed)27
  1207. b(to)h(sort)g(an)m(y)f(blo)s(c)m(k,)h(no)f(matter)h(ho)m(w)f(rep)s
  1208. (etitiv)m(e,)h(in)d(O(N)j(log)f(N))h(time.)39 b(Subsequen)m(t)330
  1209. 2699 y(w)m(ork)25 b(b)m(y)f(Kunihik)m(o)f(Sadak)-5 b(ane)24
  1210. b(has)h(pro)s(duced)e(a)i(deriv)-5 b(ativ)m(e)24 b(O(N)h((log)g(N))p
  1211. Fj(^)p Fl(2))h(algorithm)d(whic)m(h)330 2808 y(usually)28
  1212. b(outp)s(erforms)h(the)i(Man)m(b)s(er-My)m(ers)g(algorithm.)330
  1213. 2936 y(I)g(could)g(ha)m(v)m(e)i(c)m(hanged)f(to)g(Sadak)-5
  1214. b(ane's)32 b(algorithm,)f(but)g(I)g(14nd)f(it)h(to)h(b)s(e)f(slo)m(w)
  1215. m(er)h(than)f Fj(bzip2)p Fl('s)330 3045 y(existing)38
  1216. b(algorithm)g(for)h(most)h(inputs,)f(and)g(the)g(randomisation)f(mec)m
  1217. (hanism)g(protects)i(ade-)330 3155 y(quately)34 b(against)f(bad)g
  1218. (cases.)52 b(I)33 b(didn't)f(think)g(it)i(w)m(as)g(a)g(go)s(o)s(d)f
  1219. (tradeo13)i(to)f(mak)m(e.)51 b(P)m(artly)34 b(this)330
  1220. 3264 y(is)39 b(due)h(to)h(the)f(fact)h(that)g(I)f(w)m(as)g(not)h(15o)
  1221. s(o)s(ded)e(with)g(email)g(complain)m(ts)g(ab)s(out)h
  1222. Fj(bzip2-0.1)p Fl('s)330 3374 y(p)s(erformance)30 b(on)g(rep)s(etitiv)m
  1223. (e)g(data,)h(so)g(p)s(erhaps)d(it)i(isn't)g(a)h(problem)d(for)j(real)f
  1224. (inputs.)330 3501 y(Probably)h(the)h(b)s(est)g(long-term)h(solution)d
  1225. (is)i(to)h(use)f(the)g(existing)g(sorting)f(algorithm)h(initially)-8
  1226. b(,)330 3611 y(and)32 b(fall)g(bac)m(k)i(to)g(a)f(O(N)g((log)h(N))p
  1227. Fj(^)p Fl(2))g(algorithm)e(if)g(the)h(standard)f(algorithm)g(gets)i
  1228. (in)m(to)f(di16-)330 3720 y(culties.)39 b(This)27 b(can)j(b)s(e)e
  1229. (done)h(without)f(m)m(uc)m(h)h(di16cult)m(y;)f(I)g(made)h(a)h(protot)
  1230. m(yp)s(e)f(implemen)m(tation)330 3830 y(of)i(it)e(some)i(mon)m(ths)f
  1231. (no)m(w.)225 3957 y Fi(17)60 b Fl(The)31 b(compressed)f(14le)g
  1232. (format)i(w)m(as)f(nev)m(er)h(designed)d(to)j(b)s(e)f(handled)e(b)m(y)i
  1233. (a)g(library)-8 b(,)29 b(and)i(I)g(ha)m(v)m(e)330 4067
  1234. y(had)d(to)i(jump)e(though)g(some)i(ho)s(ops)e(to)i(pro)s(duce)e(an)h
  1235. (e16cien)m(t)g(implemen)m(tation)f(of)h(decompres-)330
  1236. 4177 y(sion.)38 b(It's)26 b(a)h(bit)e(hairy)-8 b(.)38
  1237. b(T)-8 b(ry)26 b(passing)f Fj(decompress.c)d Fl(through)k(the)g(C)f
  1238. (prepro)s(cessor)g(and)h(y)m(ou'll)330 4286 y(see)32
  1239. b(what)g(I)f(mean.)45 b(Muc)m(h)32 b(of)g(this)e(complexit)m(y)i(could)
  1240. f(ha)m(v)m(e)i(b)s(een)e(a)m(v)m(oided)h(if)e(the)i(compressed)330
  1241. 4396 y(size)e(of)h(eac)m(h)g(blo)s(c)m(k)f(of)h(data)g(w)m(as)g
  1242. (recorded)f(in)f(the)h(data)h(stream.)225 4523 y Fi(17)60
  1243. b Fl(An)30 b(Adler-32)g(c)m(hec)m(ksum,)i(rather)e(than)g(a)h(CR)m(C32)
  1244. g(c)m(hec)m(ksum,)g(w)m(ould)e(b)s(e)h(faster)h(to)g(compute.)150
  1245. 4698 y(It)e(w)m(ould)f(b)s(e)g(fair)g(to)h(sa)m(y)h(that)g(the)f
  1246. Fj(bzip2)e Fl(format)i(w)m(as)h(frozen)f(b)s(efore)f(I)h(prop)s(erly)d
  1247. (and)j(fully)d(under-)150 4807 y(sto)s(o)s(d)k(the)h(p)s(erformance)e
  1248. (consequences)i(of)g(doing)e(so.)150 4964 y(Impro)m(v)m(emen)m(ts)i
  1249. (whic)m(h)f(I)g(ha)m(v)m(e)i(b)s(een)e(able)g(to)i(incorp)s(orate)e(in)
  1250. m(to)g(0.9.0,)j(despite)d(using)f(the)i(same)g(14le)150
  1251. 5074 y(format,)g(are:)225 5230 y Fi(17)60 b Fl(Single)30
  1252. b(arra)m(y)i(implemen)m(tation)e(of)h(the)h(in)m(v)m(erse)f(BWT.)h
  1253. (This)e(signi14can)m(tly)f(sp)s(eeds)i(up)f(decom-)330
  1254. 5340 y(pression,)f(presumably)f(b)s(ecause)i(it)g(reduces)g(the)h(n)m
  1255. (um)m(b)s(er)e(of)i(cac)m(he)h(misses.)p eop
  1256. %%Page: 32 33
  1257. 32 32 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1258. b(32)225 366 y Fi(17)60 b Fl(F)-8 b(aster)27 b(in)m(v)m(erse)e(MTF)h
  1259. (transform)f(for)g(large)h(MTF)f(v)-5 b(alues.)39 b(The)25
  1260. b(new)g(implemen)m(tation)f(is)g(based)330 476 y(on)30
  1261. b(the)h(notion)f(of)g(sliding)e(blo)s(c)m(ks)h(of)i(v)-5
  1262. b(alues.)225 636 y Fi(17)60 b Fj(bzip2-0.9.0)24 b Fl(no)m(w)k(reads)f
  1263. (and)f(writes)h(14les)f(with)g Fj(fread)g Fl(and)h
  1264. Fj(fwrite)p Fl(;)f(v)m(ersion)h(0.1)i(used)d Fj(putc)330
  1265. 746 y Fl(and)k Fj(getc)p Fl(.)39 b(Duh!)h(I'm)31 b(em)m(barrassed)f(at)
  1266. h(m)m(y)f(o)m(wn)h(moronicness)e((moronicit)m(y?))41
  1267. b(on)30 b(this)f(one.)150 953 y(F)-8 b(urther)30 b(ahead,)g(it)f(w)m
  1268. (ould)g(b)s(e)g(nice)h(to)g(b)s(e)g(able)f(to)i(do)e(random)g(access)j
  1269. (in)m(to)d(14les.)40 b(This)28 b(will)f(require)150
  1270. 1062 y(some)k(careful)e(design)h(of)g(compressed)g(14le)g(formats.)
  1271. 150 1419 y Fk(4.2)68 b(P)l(ortabilit)l(y)47 b(issues)150
  1272. 1611 y Fl(After)31 b(some)f(consideration,)g(I)g(ha)m(v)m(e)i(decided)d
  1273. (not)i(to)g(use)f(GNU)h Fj(autoconf)d Fl(to)j(con14gure)f(0.9.0.)150
  1274. 1768 y Fj(autoconf)p Fl(,)h(admirable)g(and)h(w)m(onderful)f(though)i
  1275. (it)f(is,)h(mainly)d(assists)j(with)e(p)s(ortabilit)m(y)g(problems)150
  1276. 1878 y(b)s(et)m(w)m(een)f(Unix-lik)m(e)d(platforms.)40
  1277. b(But)29 b Fj(bzip2)f Fl(do)s(esn't)h(ha)m(v)m(e)h(m)m(uc)m(h)f(in)f
  1278. (the)h(w)m(a)m(y)h(of)g(p)s(ortabilit)m(y)d(prob-)150
  1279. 1987 y(lems)35 b(on)h(Unix;)j(most)d(of)g(the)h(di16culties)d(app)s
  1280. (ear)h(when)g(p)s(orting)g(to)i(the)f(Mac,)j(or)d(to)h(Microsoft's)150
  1281. 2097 y(op)s(erating)26 b(systems.)40 b Fj(autoconf)25
  1282. b Fl(do)s(esn't)h(help)g(in)f(those)j(cases,)h(and)d(brings)f(in)g(a)j
  1283. (whole)e(load)g(of)h(new)150 2206 y(complexit)m(y)-8
  1284. b(.)150 2363 y(Most)28 b(p)s(eople)f(should)f(b)s(e)h(able)g(to)h
  1285. (compile)e(the)i(library)d(and)i(program)h(under)e(Unix)g(straigh)m(t)i
  1286. (out-of-)150 2473 y(the-b)s(o)m(x,)j(so)g(to)g(sp)s(eak,)f(esp)s
  1287. (ecially)f(if)g(y)m(ou)i(ha)m(v)m(e)g(a)g(v)m(ersion)f(of)g(GNU)h(C)f
  1288. (a)m(v)-5 b(ailable.)150 2630 y(There)32 b(are)h(a)g(couple)f(of)h
  1289. Fj(__inline__)d Fl(directiv)m(es)i(in)f(the)i(co)s(de.)48
  1290. b(GNU)33 b(C)f(()p Fj(gcc)p Fl())g(should)f(b)s(e)h(able)g(to)150
  1291. 2739 y(handle)26 b(them.)40 b(If)28 b(y)m(our)g(compiler)e(do)s(esn't)i
  1292. (lik)m(e)f(them,)h(just)g Fj(#define)e(__inline__)f Fl(to)j(b)s(e)g(n)m
  1293. (ull.)37 b(One)150 2849 y(easy)27 b(w)m(a)m(y)g(to)g(do)f(this)e(is)i
  1294. (to)g(compile)f(with)g(the)h(15ag)h Fj(-D__inline__=)p
  1295. Fl(,)c(whic)m(h)i(should)f(b)s(e)i(understo)s(o)s(d)150
  1296. 2958 y(b)m(y)k(most)h(Unix)e(compilers.)150 3115 y(If)35
  1297. b(y)m(ou)g(still)e(ha)m(v)m(e)j(di16culties,)e(try)h(compiling)e
  1298. (with)g(the)j(macro)f Fj(BZ_STRICT_ANSI)c Fl(de14ned.)54
  1299. b(This)150 3225 y(should)28 b(enable)i(y)m(ou)h(to)g(build)d(the)i
  1300. (library)e(in)h(a)i(strictly)f(ANSI)g(complian)m(t)f(en)m(vironmen)m
  1301. (t.)41 b(Building)150 3334 y(the)25 b(program)f(itself)f(lik)m(e)g
  1302. (this)h(is)f(dangerous)h(and)g(not)g(supp)s(orted,)g(since)g(y)m(ou)h
  1303. (remo)m(v)m(e)g Fj(bzip2)p Fl('s)e(c)m(hec)m(ks)150 3444
  1304. y(against)30 b(compressing)f(directories,)g(sym)m(b)s(olic)g(links,)f
  1305. (devices,)i(and)f(other)h(not-really-a-14le)g(en)m(tities.)150
  1306. 3554 y(This)f(could)g(cause)i(14lesystem)f(corruption!)150
  1307. 3710 y(One)e(other)i(thing:)39 b(if)27 b(y)m(ou)j(create)g(a)f
  1308. Fj(bzip2)f Fl(binary)f(for)i(public)d(distribution,)g(please)i(try)h
  1309. (and)g(link)d(it)150 3820 y(statically)g(()p Fj(gcc)k(-s)p
  1310. Fl().)39 b(This)25 b(a)m(v)m(oids)i(all)f(sorts)h(of)g(library-v)m
  1311. (ersion)d(issues)h(that)i(others)g(ma)m(y)g(encoun)m(ter)150
  1312. 3930 y(later)j(on.)150 4286 y Fk(4.3)68 b(Rep)t(orting)46
  1313. b(bugs)150 4478 y Fl(I)25 b(tried)f(prett)m(y)i(hard)e(to)i(mak)m(e)g
  1314. (sure)f Fj(bzip2)e Fl(is)i(bug)f(free,)j(b)s(oth)d(b)m(y)h(design)f
  1315. (and)h(b)m(y)g(testing.)39 b(Hop)s(efully)150 4588 y(y)m(ou'll)29
  1316. b(nev)m(er)i(need)f(to)h(read)g(this)e(section)h(for)h(real.)150
  1317. 4745 y(Nev)m(ertheless,)36 b(if)c Fj(bzip2)h Fl(dies)g(with)f(a)i
  1318. (segmen)m(tation)h(fault,)g(a)f(bus)f(error)g(or)h(an)g(in)m(ternal)e
  1319. (assertion)150 4854 y(failure,)i(it)h(will)d(ask)j(y)m(ou)g(to)g(email)
  1320. f(me)h(a)g(bug)f(rep)s(ort.)54 b(Exp)s(erience)33 b(with)h(v)m(ersion)g
  1321. (0.1)i(sho)m(ws)e(that)150 4964 y(almost)c(all)g(these)h(problems)d
  1322. (can)j(b)s(e)f(traced)h(to)g(either)f(compiler)e(bugs)i(or)g(hardw)m
  1323. (are)g(problems.)225 5121 y Fi(17)60 b Fl(Recompile)22
  1324. b(the)h(program)g(with)f(no)h(optimisation,)g(and)f(see)i(if)e(it)g(w)m
  1325. (orks.)39 b(And/or)22 b(try)h(a)g(di13eren)m(t)330
  1326. 5230 y(compiler.)77 b(I)43 b(heard)f(all)g(sorts)h(of)h(stories)e(ab)s
  1327. (out)h(v)-5 b(arious)42 b(15a)m(v)m(ours)h(of)h(GNU)f(C)g((and)g
  1328. (other)330 5340 y(compilers))20 b(generating)i(bad)e(co)s(de)i(for)f
  1329. Fj(bzip2)p Fl(,)h(and)f(I'v)m(e)h(run)e(across)i(t)m(w)m(o)g(suc)m(h)f
  1330. (examples)g(m)m(yself.)p eop
  1331. %%Page: 33 34
  1332. 33 33 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1333. b(33)330 366 y(2.7.X)35 b(v)m(ersions)e(of)g(GNU)h(C)f(are)h(kno)m(wn)f
  1334. (to)h(generate)h(bad)d(co)s(de)i(from)f(time)g(to)h(time,)g(at)g(high)
  1335. 330 476 y(optimisation)20 b(lev)m(els.)37 b(If)21 b(y)m(ou)g(get)i
  1336. (problems,)e(try)g(using)f(the)i(15ags)f Fj(-O2)f
  1337. (-fomit-frame-pointer)330 586 y(-fno-strength-reduce)p
  1338. Fl(.)35 b(Y)-8 b(ou)31 b(should)d(sp)s(eci14cally)h
  1339. Fc(not)j Fl(use)e Fj(-funroll-loops)p Fl(.)330 716 y(Y)-8
  1340. b(ou)35 b(ma)m(y)g(notice)g(that)h(the)f(Mak)m(e14le)g(runs)e(four)h
  1341. (tests)i(as)e(part)h(of)g(the)g(build)c(pro)s(cess.)54
  1342. b(If)34 b(the)330 826 y(program)43 b(passes)g(all)f(of)h(these,)k(it's)
  1343. c(a)h(prett)m(y)f(go)s(o)s(d)g((but)g(not)g(10045))i(indication)c
  1344. (that)j(the)330 935 y(compiler)29 b(has)h(done)g(its)g(job)g(correctly)
  1345. -8 b(.)225 1066 y Fi(17)60 b Fl(If)33 b Fj(bzip2)f
  1346. Fl(crashes)i(randomly)-8 b(,)33 b(and)g(the)h(crashes)g(are)g(not)g
  1347. (rep)s(eatable,)g(y)m(ou)g(ma)m(y)g(ha)m(v)m(e)h(a)f(15aky)330
  1348. 1176 y(memory)k(subsystem.)64 b Fj(bzip2)37 b Fl(really)g(hammers)h(y)m
  1349. (our)g(memory)g(hierarc)m(h)m(y)-8 b(,)41 b(and)d(if)f(it's)h(a)h(bit)
  1350. 330 1285 y(marginal,)33 b(y)m(ou)h(ma)m(y)g(get)h(these)f(problems.)49
  1351. b(Ditto)34 b(if)f(y)m(our)h(disk)e(or)h(I/O)h(subsystem)e(is)h(slo)m
  1352. (wly)330 1395 y(failing.)39 b(Y)-8 b(up,)30 b(this)f(really)g(do)s(es)h
  1353. (happ)s(en.)330 1526 y(T)-8 b(ry)28 b(using)f(a)i(di13eren)m(t)f(mac)
  1354. m(hine)g(of)h(the)g(same)f(t)m(yp)s(e,)i(and)e(see)h(if)e(y)m(ou)i(can)
  1355. g(rep)s(eat)g(the)f(problem.)225 1656 y Fi(17)60 b
  1356. Fl(This)21 b(isn't)i(really)f(a)h(bug,)i(but)d(...)39
  1357. b(If)23 b Fj(bzip2)f Fl(tells)g(y)m(ou)h(y)m(our)h(14le)e(is)g
  1358. (corrupted)h(on)g(decompression,)330 1766 y(and)29 b(y)m(ou)g(obtained)
  1359. f(the)i(14le)e(via)h(FTP)-8 b(,)29 b(there)h(is)e(a)h(p)s(ossibilit)m
  1360. (y)d(that)k(y)m(ou)f(forgot)h(to)g(tell)e(FTP)h(to)330
  1361. 1875 y(do)23 b(a)g(binary)e(mo)s(de)i(transfer.)38 b(That)23
  1362. b(absolutely)f(will)e(cause)j(the)h(14le)e(to)h(b)s(e)g
  1363. (non-decompressible.)330 1985 y(Y)-8 b(ou'll)30 b(ha)m(v)m(e)h(to)g
  1364. (transfer)f(it)g(again.)150 2163 y(If)i(y)m(ou'v)m(e)h(incorp)s(orated)
  1365. e Fj(libbzip2)f Fl(in)m(to)i(y)m(our)g(o)m(wn)g(program)g(and)g(are)g
  1366. (getting)h(problems,)e(please,)150 2272 y(please,)d(please,)h(c)m(hec)m
  1367. (k)g(that)f(the)g(parameters)g(y)m(ou)g(are)g(passing)f(in)f(calls)h
  1368. (to)h(the)g(library)-8 b(,)26 b(are)j(correct,)150 2382
  1369. y(and)e(in)f(accordance)k(with)c(what)i(the)g(do)s(cumen)m(tation)f(sa)
  1370. m(ys)h(is)f(allo)m(w)m(able.)39 b(I)28 b(ha)m(v)m(e)h(tried)e(to)h(mak)
  1371. m(e)h(the)150 2492 y(library)f(robust)i(against)g(suc)m(h)g(problems,)f
  1372. (but)h(I'm)g(sure)g(I)g(ha)m(v)m(en't)h(succeeded.)150
  1373. 2648 y(Finally)-8 b(,)32 b(if)g(the)h(ab)s(o)m(v)m(e)i(commen)m(ts)e
  1374. (don't)g(help,)g(y)m(ou'll)f(ha)m(v)m(e)i(to)g(send)e(me)h(a)g(bug)g
  1375. (rep)s(ort.)48 b(No)m(w,)34 b(it's)150 2758 y(just)c(amazing)g(ho)m(w)h
  1376. (man)m(y)f(p)s(eople)g(will)d(send)j(me)g(a)h(bug)f(rep)s(ort)g(sa)m
  1377. (ying)g(something)g(lik)m(e)481 2909 y(bzip2)f(crashed)h(with)f(segmen)
  1378. m(tation)j(fault)e(on)g(m)m(y)g(mac)m(hine)150 3066 y(and)h(absolutely)
  1379. f(nothing)h(else.)44 b(Needless)32 b(to)g(sa)m(y)-8 b(,)33
  1380. b(a)f(suc)m(h)f(a)h(rep)s(ort)f(is)g Fc(totally)-8 b(,)32
  1381. b(utterly)-8 b(,)32 b(completely)150 3175 y(and)40 b(comprehensiv)m
  1382. (ely)g(10045)h(useless;)46 b(a)41 b(w)m(aste)g(of)g(y)m(our)g(time,)i
  1383. (m)m(y)e(time,)i(and)e(net)g(bandwidth)p Fl(.)150 3285
  1384. y(With)31 b(no)h(details)f(at)i(all,)e(there's)h(no)g(w)m(a)m(y)h(I)f
  1385. (can)g(p)s(ossibly)d(b)s(egin)h(to)j(14gure)e(out)i(what)e(the)i
  1386. (problem)150 3395 y(is.)150 3551 y(The)d(rules)e(of)i(the)g(game)h
  1387. (are:)41 b(facts,)32 b(facts,)f(facts.)41 b(Don't)31
  1388. b(omit)f(them)g(b)s(ecause)g Fj(")p Fl(oh,)g(they)g(w)m(on't)h(b)s(e)
  1389. 150 3661 y(relev)-5 b(an)m(t)p Fj(")p Fl(.)41 b(A)m(t)31
  1390. b(the)g(bare)f(minim)m(um:)481 3812 y(Mac)m(hine)h(t)m(yp)s(e.)61
  1391. b(Op)s(erating)29 b(system)h(v)m(ersion.)481 3916 y(Exact)h(v)m(ersion)
  1392. f(of)h Fj(bzip2)e Fl((do)h Fj(bzip2)47 b(-V)p Fl().)481
  1393. 4020 y(Exact)31 b(v)m(ersion)f(of)h(the)f(compiler)f(used.)481
  1394. 4123 y(Flags)i(passed)e(to)j(the)e(compiler.)150 4280
  1395. y(Ho)m(w)m(ev)m(er,)i(the)d(most)h(imp)s(ortan)m(t)f(single)f(thing)g
  1396. (that)i(will)d(help)h(me)h(is)f(the)i(14le)e(that)i(y)m(ou)g(w)m(ere)
  1397. g(trying)150 4390 y(to)f(compress)f(or)g(decompress)g(at)h(the)f(time)g
  1398. (the)g(problem)f(happ)s(ened.)38 b(Without)28 b(that,)h(m)m(y)g(abilit)
  1399. m(y)d(to)150 4499 y(do)k(an)m(ything)g(more)h(than)f(sp)s(eculate)g(ab)
  1400. s(out)g(the)g(cause,)i(is)d(limited.)150 4656 y(Please)34
  1401. b(remem)m(b)s(er)f(that)h(I)f(connect)i(to)f(the)g(In)m(ternet)g(with)e
  1402. (a)i(mo)s(dem,)g(so)f(y)m(ou)h(should)e(con)m(tact)k(me)150
  1403. 4766 y(b)s(efore)30 b(mailing)e(me)j(h)m(uge)f(14les.)150
  1404. 5038 y Fk(4.4)68 b(Did)45 b(y)l(ou)g(get)h(the)f(righ)l(t)h(pac)l(k)-7
  1405. b(age?)150 5230 y Fj(bzip2)34 b Fl(is)h(a)h(resource)g(hog.)56
  1406. b(It)36 b(soaks)g(up)f(large)g(amoun)m(ts)h(of)g(CPU)f(cycles)h(and)f
  1407. (memory)-8 b(.)57 b(Also,)36 b(it)150 5340 y(giv)m(es)26
  1408. b(v)m(ery)h(large)f(latencies.)39 b(In)25 b(the)h(w)m(orst)g(case,)i(y)
  1409. m(ou)f(can)f(feed)g(man)m(y)g(megab)m(ytes)h(of)f(uncompressed)p
  1410. eop
  1411. %%Page: 34 35
  1412. 34 34 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1413. b(34)150 366 y(data)45 b(in)m(to)e(the)i(library)c(b)s(efore)j(getting)
  1414. g(an)m(y)g(compressed)g(output,)j(so)d(this)f(probably)f(rules)h(out)
  1415. 150 476 y(applications)29 b(requiring)e(in)m(teractiv)m(e)32
  1416. b(b)s(eha)m(viour.)150 633 y(These)38 b(aren't)h(faults)e(of)h(m)m(y)g
  1417. (implemen)m(tation,)h(I)f(hop)s(e,)i(but)d(more)h(an)g(in)m(trinsic)e
  1418. (prop)s(ert)m(y)h(of)i(the)150 742 y(Burro)m(ws-Wheeler)30
  1419. b(transform)g((unfortunately).)40 b(Ma)m(yb)s(e)31
  1420. b(this)e(isn't)h(what)g(y)m(ou)h(w)m(an)m(t.)150 899
  1421. y(If)h(y)m(ou)h(w)m(an)m(t)g(a)g(compressor)g(and/or)f(library)e(whic)m
  1422. (h)h(is)h(faster,)i(uses)e(less)g(memory)g(but)g(gets)h(prett)m(y)150
  1423. 1009 y(go)s(o)s(d)e(compression,)g(and)g(has)h(minimal)c(latency)-8
  1424. b(,)33 b(consider)e(Jean-loup)f(Gailly's)g(and)h(Mark)h(Adler's)150
  1425. 1119 y(w)m(ork,)23 b Fj(zlib-1.1.2)17 b Fl(and)j Fj(gzip-1.2.4)p
  1426. Fl(.)34 b(Lo)s(ok)21 b(for)f(them)g(at)h Fj(http://www.cdrom.com/pub)o
  1427. (/inf)o(ozip)o(/zl)o(ib)p 4036 1139 42 84 v 150 1228
  1428. a Fl(and)30 b Fj(http://www.gzip.org)25 b Fl(resp)s(ectiv)m(ely)-8
  1429. b(.)150 1385 y(F)g(or)32 b(something)f(faster)i(and)e(ligh)m(ter)f
  1430. (still,)h(y)m(ou)g(migh)m(t)h(try)f(Markus)h(F)g(X)f(J)h(Ob)s(erh)m
  1431. (umer's)d Fj(LZO)i Fl(real-)150 1495 y(time)f
  1432. (compression/decompression)f(library)-8 b(,)28 b(at)150
  1433. 1604 y Fj(http://wildsau.idv.uni-l)o(inz.)o(ac.a)o(t/m)o(fx/l)o(zo.h)o
  1434. (tml)o Fl(.)150 1761 y(If)38 b(y)m(ou)h(w)m(an)m(t)g(to)h(use)e(the)g
  1435. Fj(bzip2)g Fl(algorithms)f(to)i(compress)f(small)g(blo)s(c)m(ks)f(of)i
  1436. (data,)j(64k)d(b)m(ytes)g(or)150 1871 y(smaller,)i(for)e(example)g(on)h
  1437. (an)f(on-the-15y)h(disk)e(compressor,)k(y)m(ou'd)e(b)s(e)f(w)m(ell)g
  1438. (advised)f(not)i(to)g(use)150 1980 y(this)i(library)-8
  1439. b(.)77 b(Instead,)47 b(I'v)m(e)d(made)f(a)h(sp)s(ecial)e(library)f
  1440. (tuned)h(for)h(that)h(kind)d(of)j(use.)79 b(It's)43 b(part)150
  1441. 2090 y(of)d Fj(e2compr-0.40)p Fl(,)f(an)g(on-the-15y)h(disk)e
  1442. (compressor)h(for)h(the)f(Lin)m(ux)f Fj(ext2)h Fl(14lesystem.)67
  1443. b(Lo)s(ok)40 b(at)150 2199 y Fj(http://www.netspace.net.)o(au/~)o(reit)
  1444. o(er/)o(e2co)o(mpr)p Fl(.)150 2490 y Fk(4.5)68 b(T)-11
  1445. b(esting)150 2683 y Fl(A)30 b(record)h(of)f(the)h(tests)g(I'v)m(e)g
  1446. (done.)150 2840 y(First,)f(some)h(data)g(sets:)225 2996
  1447. y Fi(17)60 b Fl(B:)27 b(a)g(directory)f(con)m(taining)g(a)h(6001)h
  1448. (14les,)e(one)h(for)f(ev)m(ery)h(length)f(in)f(the)i(range)g(0)g(to)g
  1449. (6000)h(b)m(ytes.)330 3106 y(The)i(14les)f(con)m(tain)i(random)e(lo)m
  1450. (w)m(ercase)j(letters.)41 b(18.7)32 b(megab)m(ytes.)225
  1451. 3244 y Fi(17)60 b Fl(H:)36 b(m)m(y)f(home)h(directory)f(tree.)56
  1452. b(Do)s(cumen)m(ts,)38 b(source)d(co)s(de,)i(mail)d(14les,)i
  1453. (compressed)f(data.)57 b(H)330 3354 y(con)m(tains)39
  1454. b(B,)h(and)f(also)g(a)g(directory)g(of)g(14les)f(designed)g(as)i(b)s
  1455. (oundary)d(cases)j(for)f(the)g(sorting;)330 3463 y(mostly)30
  1456. b(v)m(ery)h(rep)s(etitiv)m(e,)f(nast)m(y)h(14les.)39
  1457. b(445)32 b(megab)m(ytes.)225 3602 y Fi(17)60 b Fl(A:)41
  1458. b(directory)f(tree)i(holding)d(v)-5 b(arious)39 b(applications)g(built)
  1459. g(from)h(source:)62 b Fj(egcs-1.0.2)p Fl(,)41 b Fj(gcc-)330
  1460. 3711 y(2.8.1)p Fl(,)29 b(KDE)i(Beta)g(4,)g(GTK,)g(Octa)m(v)m(e,)i(etc.)
  1461. 41 b(827)32 b(megab)m(ytes.)225 3850 y Fi(17)60 b Fl(P:)33
  1462. b(directory)f(tree)h(holding)e(large)i(amoun)m(ts)g(of)f(source)h(co)s
  1463. (de)g(()p Fj(.tar)f Fl(14les))g(of)h(the)g(en)m(tire)f(GNU)330
  1464. 3959 y(distribution,)27 b(plus)h(a)j(couple)f(of)h(Lin)m(ux)d
  1465. (distributions.)37 b(2400)32 b(megab)m(ytes.)150 4145
  1466. y(The)j(tests)g(conducted)g(are)h(as)f(follo)m(ws.)54
  1467. b(Eac)m(h)36 b(test)g(means)f(compressing)f((a)h(cop)m(y)h(of)7
  1468. b())36 b(eac)m(h)g(14le)e(in)150 4254 y(the)d(data)g(set,)g
  1469. (decompressing)e(it)h(and)g(comparing)f(it)h(against)h(the)g(original.)
  1470. 150 4411 y(First,)44 b(a)e(bunc)m(h)e(of)h(tests)h(with)f(blo)s(c)m(k)f
  1471. (sizes,)45 b(in)m(ternal)40 b(bu13er)g(sizes)h(and)g(randomisation)f
  1472. (lengths)150 4521 y(set)45 b(v)m(ery)g(small,)h(to)f(detect)h(an)m(y)f
  1473. (problems)e(with)g(the)h(blo)s(c)m(king,)j(bu13ering)c(and)h
  1474. (randomisation)150 4630 y(mec)m(hanisms.)c(This)28 b(required)h(mo)s
  1475. (difying)f(the)i(source)h(co)s(de)f(so)h(as)g(to)g(try)f(to)h(break)f
  1476. (it.)199 4787 y(1.)61 b(Data)32 b(set)f(H,)g(with)e(bu13er)g(size)h
  1477. (of)h(1)g(b)m(yte,)g(and)f(blo)s(c)m(k)g(size)g(of)g(23)i(b)m(ytes.)199
  1478. 4925 y(2.)61 b(Data)32 b(set)f(B,)g(bu13er)e(sizes)h(1)h(b)m(yte,)g
  1479. (blo)s(c)m(k)f(size)g(1)h(b)m(yte.)199 5064 y(3.)61 b(As)30
  1480. b((2))i(but)d(small-mo)s(de)g(decompression)h((14rst)g(1700)i
  1481. (14les).)199 5202 y(4.)61 b(As)30 b((2))i(with)d(blo)s(c)m(k)h
  1482. (size)g(2)h(b)m(ytes.)199 5340 y(5.)61 b(As)30 b((2))i(with)d(blo)s
  1483. (c)m(k)h(size)g(3)h(b)m(ytes.)p eop
  1484. %%Page: 35 36
  1485. 35 35 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1486. b(35)199 366 y(6.)61 b(As)30 b((2))i(with)d(blo)s(c)m(k)h(size)g(4)h
  1487. (b)m(ytes.)199 502 y(7.)61 b(As)30 b((2))i(with)d(blo)s(c)m(k)h(size)
  1488. g(5)h(b)m(ytes.)199 638 y(8.)61 b(As)30 b((2))i(with)d(blo)s(c)m(k)h
  1489. (size)g(6)h(b)m(ytes)g(and)e(small-mo)s(de)g(decompression.)199
  1490. 774 y(9.)61 b(H)34 b(with)f(normal)g(bu13er)h(sizes)f((5000)k(b)m
  1491. (ytes),)f(normal)d(blo)s(c)m(k)h(size)g((up)g(to)g(900000)j(b)m
  1492. (ytes),)g(but)330 883 y(with)i(randomisation)g(mec)m(hanism)h(running)
  1493. e(in)m(tensely)h((randomising)f(appro)m(ximately)i(ev)m(ery)330
  1494. 993 y(third)29 b(b)m(yte).)154 1128 y(10.)61 b(As)30
  1495. b((9))i(with)d(small-mo)s(de)g(decompression.)150 1311
  1496. y(Then)g(some)i(tests)g(with)e(unmo)s(di14ed)f(source)i(co)s(de.)199
  1497. 1468 y(1.)61 b(H,)31 b(all)e(settings)h(normal.)199 1604
  1498. y(2.)61 b(As)30 b((1),)i(with)d(small-mo)s(de)g(decompress.)199
  1499. 1740 y(3.)61 b(H,)31 b(compress)f(with)f(15ag)i Fj(-1)p
  1500. Fl(.)199 1875 y(4.)61 b(H,)31 b(compress)f(with)f(15ag)i
  1501. Fj(-s)p Fl(,)f(decompress)g(with)f(15ag)i Fj(-s)p Fl(.)199
  1502. 2011 y(5.)61 b(F)-8 b(orw)m(ards)33 b(compatibilit)m(y:)45
  1503. b(H,)33 b Fj(bzip2-0.1pl2)d Fl(compressing,)j Fj(bzip2-0.9.0)d
  1504. Fl(decompressing,)330 2121 y(all)f(settings)i(normal.)199
  1505. 2256 y(6.)61 b(Bac)m(kw)m(ards)23 b(compatibilit)m(y:)35
  1506. b(H,)23 b Fj(bzip2-0.9.0)c Fl(compressing,)k Fj(bzip2-0.1pl2)c
  1507. Fl(decompressing,)330 2366 y(all)29 b(settings)i(normal.)199
  1508. 2502 y(7.)61 b(Bigger)31 b(tests:)41 b(A,)31 b(all)e(settings)i
  1509. (normal.)199 2637 y(8.)61 b(P)-8 b(,)31 b(all)e(settings)h(normal.)199
  1510. 2773 y(9.)61 b(Misc)30 b(test:)42 b(ab)s(out)30 b(100)i(megab)m(ytes)f
  1511. (of)g Fj(.tar)e Fl(14les)h(with)f Fj(bzip2)g Fl(compiled)f(with)h
  1512. (Purify)-8 b(.)154 2909 y(10.)61 b(Misc)30 b(tests)h(to)g(mak)m(e)h
  1513. (sure)d(it)h(builds)e(and)h(runs)g(ok)i(on)f(non-Lin)m(ux/x86)g
  1514. (platforms.)150 3092 y(These)j(tests)g(w)m(ere)h(conducted)f(on)f(a)i
  1515. (205)g(MHz)f(Cyrix)f(6x86MX)i(mac)m(hine,)g(running)c(Lin)m(ux)h
  1516. (2.0.32.)150 3201 y(They)f(represen)m(t)g(nearly)g(a)h(w)m(eek)g(of)f
  1517. (con)m(tin)m(uous)g(computation.)41 b(All)29 b(tests)i(completed)f
  1518. (successfully)-8 b(.)150 3485 y Fk(4.6)68 b(F)-11 b(urther)44
  1519. b(reading)150 3677 y Fj(bzip2)28 b Fl(is)h(not)h(researc)m(h)g(w)m
  1520. (ork,)g(in)e(the)i(sense)g(that)g(it)f(do)s(esn't)g(presen)m(t)h(an)m
  1521. (y)g(new)f(ideas.)40 b(Rather,)30 b(it's)150 3787 y(an)g(engineering)f
  1522. (exercise)i(based)f(on)g(existing)g(ideas.)150 3944 y(F)-8
  1523. b(our)31 b(do)s(cumen)m(ts)f(describ)s(e)e(essen)m(tially)i(all)f(the)i
  1524. (ideas)e(b)s(ehind)f Fj(bzip2)p Fl(:)390 4095 y Fj(Michael)46
  1525. b(Burrows)g(and)h(D.)g(J.)g(Wheeler:)485 4198 y("A)h(block-sorting)c
  1526. (lossless)h(data)i(compression)e(algorithm")533 4302
  1527. y(10th)i(May)g(1994.)533 4406 y(Digital)f(SRC)h(Research)e(Report)i
  1528. (124.)533 4510 y(ftp://ftp.digital.com/pub)o(/DEC)o(/SR)o(C/re)o(sear)o
  1529. (ch-)o(repo)o(rts/)o(SRC)o(-124)o(.ps.)o(gz)533 4614
  1530. y(If)g(you)g(have)g(trouble)f(finding)g(it,)g(try)h(searching)f(at)h
  1531. (the)533 4717 y(New)g(Zealand)f(Digital)g(Library,)f
  1532. (http://www.nzdl.org.)390 4925 y(Daniel)h(S.)h(Hirschberg)e(and)i
  1533. (Debra)g(A.)g(LeLewer)485 5029 y("Efficient)e(Decoding)h(of)h(Prefix)f
  1534. (Codes")533 5132 y(Communications)e(of)j(the)g(ACM,)g(April)f(1990,)h
  1535. (Vol)f(33,)h(Number)f(4.)533 5236 y(You)h(might)f(be)i(able)e(to)h(get)
  1536. g(an)h(electronic)d(copy)h(of)h(this)676 5340 y(from)g(the)g(ACM)g
  1537. (Digital)f(Library.)p eop
  1538. %%Page: 36 37
  1539. 36 36 bop 150 -116 a Fl(Chapter)30 b(4:)41 b(Miscellanea)2586
  1540. b(36)390 470 y Fj(David)46 b(J.)i(Wheeler)533 574 y(Program)e(bred3.c)g
  1541. (and)h(accompanying)d(document)i(bred3.ps.)533 678 y(This)h(contains)e
  1542. (the)i(idea)g(behind)f(the)h(multi-table)e(Huffman)533
  1543. 782 y(coding)h(scheme.)533 885 y(ftp://ftp.cl.cam.ac.uk/pu)o(b/us)o
  1544. (er/)o(djw3)o(/)390 1093 y(Jon)h(L.)g(Bentley)f(and)h(Robert)f
  1545. (Sedgewick)485 1197 y("Fast)h(Algorithms)e(for)i(Sorting)f(and)g
  1546. (Searching)g(Strings")533 1300 y(Available)f(from)i(Sedgewick's)e(web)i
  1547. (page,)533 1404 y(www.cs.princeton.edu/~rs)150 1561 y
  1548. Fl(The)29 b(follo)m(wing)f(pap)s(er)g(giv)m(es)h(v)-5
  1549. b(aluable)28 b(additional)g(insigh)m(ts)f(in)m(to)j(the)f(algorithm,)g
  1550. (but)g(is)f(not)i(imme-)150 1671 y(diately)g(the)g(basis)f(of)i(an)m(y)
  1551. g(co)s(de)f(used)g(in)f(bzip2.)390 1822 y Fj(Peter)46
  1552. b(Fenwick:)533 1925 y(Block)h(Sorting)e(Text)i(Compression)533
  1553. 2029 y(Proceedings)e(of)i(the)g(19th)g(Australasian)d(Computer)i
  1554. (Science)f(Conference,)629 2133 y(Melbourne,)g(Australia.)92
  1555. b(Jan)47 b(31)g(-)h(Feb)f(2,)g(1996.)533 2237 y
  1556. (ftp://ftp.cs.auckland.ac.)o(nz/p)o(ub/)o(pete)o(r-f/)o(ACS)o(C96p)o
  1557. (aper)o(.ps)150 2394 y Fl(Kunihik)m(o)28 b(Sadak)-5 b(ane's)31
  1558. b(sorting)e(algorithm,)h(men)m(tioned)g(ab)s(o)m(v)m(e,)i(is)d(a)m(v)-5
  1559. b(ailable)30 b(from:)390 2545 y Fj(http://naomi.is.s.u-toky)o(o.ac)o
  1560. (.jp/)o(~sa)o(da/p)o(aper)o(s/S)o(ada9)o(8b.p)o(s.g)o(z)150
  1561. 2702 y Fl(The)41 b(Man)m(b)s(er-My)m(ers)g(su16x)g(arra)m(y)g
  1562. (construction)g(algorithm)f(is)g(describ)s(ed)f(in)h(a)i(pap)s(er)e(a)m
  1563. (v)-5 b(ailable)150 2811 y(from:)390 2962 y Fj
  1564. (http://www.cs.arizona.ed)o(u/pe)o(ople)o(/ge)o(ne/P)o(APER)o(S/s)o
  1565. (uffi)o(x.ps)p eop
  1566. %%Page: -1 38
  1567. -1 37 bop 3725 -116 a Fl(i)150 366 y Fh(T)-13 b(able)54
  1568. b(of)g(Con)l(ten)l(ts)150 684 y Fk(1)135 b(In)l(tro)t(duction)15
  1569. b Fb(.)20 b(.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f
  1570. (.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)60
  1571. b Fk(2)150 942 y(2)135 b(Ho)l(w)45 b(to)h(use)f Fd(bzip2)31
  1572. b Fb(.)19 b(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)g
  1573. (.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)78 b Fk(3)150
  1574. 1201 y(3)135 b(Programming)46 b(with)f Fd(libbzip2)27
  1575. b Fb(.)16 b(.)j(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)72
  1576. b Fk(11)449 1338 y Fl(3.1)92 b(T)-8 b(op-lev)m(el)30
  1577. b(structure)23 b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1578. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)
  1579. g(.)g(.)g(.)g(.)g(.)g(.)g(.)52 b Fl(11)748 1447 y(3.1.1)93
  1580. b(Lo)m(w-lev)m(el)30 b(summary)22 b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g
  1581. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1582. g(.)g(.)g(.)52 b Fl(11)748 1557 y(3.1.2)93 b(High-lev)m(el)29
  1583. b(summary)10 b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1584. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)40
  1585. b Fl(11)748 1666 y(3.1.3)93 b(Utilit)m(y)29 b(functions)g(summary)12
  1586. b Fa(.)h(.)j(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1587. g(.)g(.)g(.)g(.)g(.)41 b Fl(12)449 1776 y(3.2)92 b(Error)29
  1588. b(handling)18 b Fa(.)13 b(.)i(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f
  1589. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1590. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)48 b Fl(12)449
  1591. 1886 y(3.3)92 b(Lo)m(w-lev)m(el)31 b(in)m(terface)d Fa(.)15
  1592. b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g
  1593. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1594. g(.)57 b Fl(14)748 1995 y(3.3.1)93 b Fj(bzCompressInit)9
  1595. b Fa(.)h(.)15 b(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1596. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)38
  1597. b Fl(14)748 2105 y(3.3.2)93 b Fj(bzCompress)18 b Fa(.)12
  1598. b(.)j(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1599. (.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)47
  1600. b Fl(15)748 2214 y(3.3.3)93 b Fj(bzCompressEnd)11 b Fa(.)g(.)k(.)g(.)g
  1601. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)
  1602. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)40 b Fl(18)748
  1603. 2324 y(3.3.4)93 b Fj(bzDecompressInit)21 b Fa(.)15 b(.)g(.)g(.)g(.)g(.)
  1604. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1605. (.)g(.)g(.)g(.)g(.)55 b Fl(18)748 2434 y(3.3.5)93 b Fj(bzDecompress)13
  1606. b Fa(.)f(.)j(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1607. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)43
  1608. b Fl(19)748 2543 y(3.3.6)93 b Fj(bzDecompressEnd)23 b
  1609. Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g
  1610. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)57
  1611. b Fl(20)449 2653 y(3.4)92 b(High-lev)m(el)30 b(in)m(terface)16
  1612. b Fa(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1613. h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1614. (.)g(.)g(.)45 b Fl(20)748 2762 y(3.4.1)93 b Fj(bzReadOpen)18
  1615. b Fa(.)12 b(.)j(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1616. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1617. g(.)47 b Fl(21)748 2872 y(3.4.2)93 b Fj(bzRead)25 b Fa(.)15
  1618. b(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1619. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1620. g(.)g(.)g(.)57 b Fl(22)748 2982 y(3.4.3)93 b Fj(bzReadGetUnused)23
  1621. b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g
  1622. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)57
  1623. b Fl(23)748 3091 y(3.4.4)93 b Fj(bzReadClose)16 b Fa(.)11
  1624. b(.)k(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g
  1625. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)45
  1626. b Fl(23)748 3201 y(3.4.5)93 b Fj(bzWriteOpen)16 b Fa(.)11
  1627. b(.)k(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g
  1628. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)45
  1629. b Fl(24)748 3310 y(3.4.6)93 b Fj(bzWrite)23 b Fa(.)15
  1630. b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1631. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)
  1632. g(.)g(.)54 b Fl(24)748 3420 y(3.4.7)93 b Fj(bzWriteClose)13
  1633. b Fa(.)f(.)j(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1634. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)43
  1635. b Fl(25)748 3530 y(3.4.8)93 b(Handling)28 b(em)m(b)s(edded)h
  1636. (compressed)h(data)h(streams)17 b Fa(.)f(.)f(.)g(.)46
  1637. b Fl(25)748 3639 y(3.4.9)93 b(Standard)29 b(14le-reading/writing)e
  1638. (co)s(de)22 b Fa(.)16 b(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1639. (.)52 b Fl(26)449 3749 y(3.5)92 b(Utilit)m(y)29 b(functions)f
  1640. Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1641. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1642. g(.)g(.)g(.)g(.)g(.)59 b Fl(27)748 3858 y(3.5.1)93 b
  1643. Fj(bzBuffToBuffCompress)16 b Fa(.)9 b(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1644. g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)45
  1645. b Fl(27)748 3968 y(3.5.2)93 b Fj(bzBuffToBuffDecompress)10
  1646. b Fa(.)g(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1647. (.)g(.)g(.)g(.)g(.)g(.)41 b Fl(28)449 4077 y(3.6)92 b(Using)30
  1648. b(the)g(library)e(in)h(a)i Fj(stdio)p Fl(-free)e(en)m(vironmen)m(t)23
  1649. b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)52
  1650. b Fl(29)748 4187 y(3.6.1)93 b(Getting)31 b(rid)d(of)j
  1651. Fj(stdio)20 b Fa(.)13 b(.)i(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f
  1652. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)49
  1653. b Fl(29)748 4297 y(3.6.2)93 b(Critical)28 b(error)i(handling)22
  1654. b Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1655. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)54 b Fl(29)449 4406
  1656. y(3.7)92 b(Making)30 b(a)h(Windo)m(ws)e(DLL)15 b Fa(.)h(.)f(.)g(.)g(.)g
  1657. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1658. g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)44 b Fl(30)150 4637
  1659. y Fk(4)135 b(Miscellanea)11 b Fb(.)21 b(.)f(.)f(.)h(.)f(.)g(.)h(.)f(.)h
  1660. (.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)h(.)f(.)
  1661. h(.)f(.)g(.)h(.)56 b Fk(31)449 4774 y Fl(4.1)92 b(Limitations)29
  1662. b(of)h(the)h(compressed)f(14le)f(format)9 b Fa(.)15
  1663. b(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)38
  1664. b Fl(31)449 4884 y(4.2)92 b(P)m(ortabilit)m(y)30 b(issues)14
  1665. b Fa(.)f(.)j(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1666. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1667. (.)g(.)h(.)f(.)g(.)43 b Fl(32)449 4994 y(4.3)92 b(Rep)s(orting)29
  1668. b(bugs)f Fa(.)15 b(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1669. (.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1670. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)58 b Fl(32)449 5103 y(4.4)92
  1671. b(Did)29 b(y)m(ou)i(get)h(the)e(righ)m(t)g(pac)m(k)-5
  1672. b(age?)22 b Fa(.)17 b(.)e(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h
  1673. (.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)51
  1674. b Fl(33)449 5213 y(4.5)92 b(T)-8 b(esting)16 b Fa(.)f(.)g(.)g(.)g(.)g
  1675. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1676. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g
  1677. (.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)45 b Fl(34)449 5322 y(4.6)92
  1678. b(F)-8 b(urther)30 b(reading)22 b Fa(.)14 b(.)h(.)g(.)h(.)f(.)g(.)g(.)g
  1679. (.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)
  1680. g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)g(.)h(.)f(.)51
  1681. b Fl(35)p eop
  1682. %%Trailer
  1683. end
  1684. userdict /end-hook known{end-hook}if
  1685. %%EOF