You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

525 lines
16 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>journal - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package journal</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "github.com/syndtr/goleveldb/leveldb/journal"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package journal reads and writes sequences of journals. Each journal is a stream
  68. of bytes that completes before the next journal starts.
  69. </p>
  70. <p>
  71. When reading, call Next to obtain an io.Reader for the next journal. Next will
  72. return io.EOF when there are no more journals. It is valid to call Next
  73. without reading the current journal to exhaustion.
  74. </p>
  75. <p>
  76. When writing, call Next to obtain an io.Writer for the next journal. Calling
  77. Next finishes the current journal. Call Close to finish the final journal.
  78. </p>
  79. <p>
  80. Optionally, call Flush to finish the current journal and flush the underlying
  81. writer without starting a new journal. To start a new journal after flushing,
  82. call Next.
  83. </p>
  84. <p>
  85. Neither Readers or Writers are safe to use concurrently.
  86. </p>
  87. <p>
  88. Example code:
  89. </p>
  90. <pre>func read(r io.Reader) ([]string, error) {
  91. var ss []string
  92. journals := journal.NewReader(r, nil, true, true)
  93. for {
  94. j, err := journals.Next()
  95. if err == io.EOF {
  96. break
  97. }
  98. if err != nil {
  99. return nil, err
  100. }
  101. s, err := ioutil.ReadAll(j)
  102. if err != nil {
  103. return nil, err
  104. }
  105. ss = append(ss, string(s))
  106. }
  107. return ss, nil
  108. }
  109. func write(w io.Writer, ss []string) error {
  110. journals := journal.NewWriter(w)
  111. for _, s := range ss {
  112. j, err := journals.Next()
  113. if err != nil {
  114. return err
  115. }
  116. if _, err := j.Write([]byte(s)), err != nil {
  117. return err
  118. }
  119. }
  120. return journals.Close()
  121. }
  122. </pre>
  123. <p>
  124. The wire format is that the stream is divided into 32KiB blocks, and each
  125. block contains a number of tightly packed chunks. Chunks cannot cross block
  126. boundaries. The last block may be shorter than 32 KiB. Any unused bytes in a
  127. block must be zero.
  128. </p>
  129. <p>
  130. A journal maps to one or more chunks. Each chunk has a 7 byte header (a 4
  131. byte checksum, a 2 byte little-endian uint16 length, and a 1 byte chunk type)
  132. followed by a payload. The checksum is over the chunk type and the payload.
  133. </p>
  134. <p>
  135. There are four chunk types: whether the chunk is the full journal, or the
  136. first, middle or last chunk of a multi-chunk journal. A multi-chunk journal
  137. has one first chunk, zero or more middle chunks, and one last chunk.
  138. </p>
  139. <p>
  140. The wire format allows for limited recovery in the face of data corruption:
  141. on a format error (such as a checksum mismatch), the reader moves to the
  142. next block and looks for the next full or first chunk.
  143. </p>
  144. </div>
  145. </div>
  146. <div id="pkg-index" class="toggleVisible">
  147. <div class="collapsed">
  148. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  149. </div>
  150. <div class="expanded">
  151. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  152. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  153. <div id="manual-nav">
  154. <dl>
  155. <dd><a href="index.html#Dropper">type Dropper</a></dd>
  156. <dd><a href="index.html#ErrCorrupted">type ErrCorrupted</a></dd>
  157. <dd>&nbsp; &nbsp; <a href="index.html#ErrCorrupted.Error">func (e *ErrCorrupted) Error() string</a></dd>
  158. <dd><a href="index.html#Reader">type Reader</a></dd>
  159. <dd>&nbsp; &nbsp; <a href="index.html#NewReader">func NewReader(r io.Reader, dropper Dropper, strict, checksum bool) *Reader</a></dd>
  160. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Next">func (r *Reader) Next() (io.Reader, error)</a></dd>
  161. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Reset">func (r *Reader) Reset(reader io.Reader, dropper Dropper, strict, checksum bool) error</a></dd>
  162. <dd><a href="index.html#Writer">type Writer</a></dd>
  163. <dd>&nbsp; &nbsp; <a href="index.html#NewWriter">func NewWriter(w io.Writer) *Writer</a></dd>
  164. <dd>&nbsp; &nbsp; <a href="index.html#Writer.Close">func (w *Writer) Close() error</a></dd>
  165. <dd>&nbsp; &nbsp; <a href="index.html#Writer.Flush">func (w *Writer) Flush() error</a></dd>
  166. <dd>&nbsp; &nbsp; <a href="index.html#Writer.Next">func (w *Writer) Next() (io.Writer, error)</a></dd>
  167. <dd>&nbsp; &nbsp; <a href="index.html#Writer.Reset">func (w *Writer) Reset(writer io.Writer) (err error)</a></dd>
  168. </dl>
  169. </div><!-- #manual-nav -->
  170. <h4>Package files</h4>
  171. <p>
  172. <span style="font-size:90%">
  173. <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go">journal.go</a>
  174. </span>
  175. </p>
  176. </div><!-- .expanded -->
  177. </div><!-- #pkg-index -->
  178. <div id="pkg-callgraph" class="toggle" style="display: none">
  179. <div class="collapsed">
  180. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  181. </div> <!-- .expanded -->
  182. <div class="expanded">
  183. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  184. <p>
  185. In the call graph viewer below, each node
  186. is a function belonging to this package
  187. and its children are the functions it
  188. calls&mdash;perhaps dynamically.
  189. </p>
  190. <p>
  191. The root nodes are the entry points of the
  192. package: functions that may be called from
  193. outside the package.
  194. There may be non-exported or anonymous
  195. functions among them if they are called
  196. dynamically from another package.
  197. </p>
  198. <p>
  199. Click a node to visit that function's source code.
  200. From there you can visit its callers by
  201. clicking its declaring <code>func</code>
  202. token.
  203. </p>
  204. <p>
  205. Functions may be omitted if they were
  206. determined to be unreachable in the
  207. particular programs or tests that were
  208. analyzed.
  209. </p>
  210. <!-- Zero means show all package entry points. -->
  211. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  212. </div>
  213. </div> <!-- #pkg-callgraph -->
  214. <h2 id="Dropper">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=3899:3942#L109">Dropper</a></h2>
  215. <pre>type Dropper interface {
  216. Drop(err <a href="../../../../../builtin/index.html#error">error</a>)
  217. }</pre>
  218. <p>
  219. Dropper is the interface that wrap simple Drop method. The Drop
  220. method will be called when the journal reader dropping a block or chunk.
  221. </p>
  222. <h2 id="ErrCorrupted">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=3561:3616#L98">ErrCorrupted</a></h2>
  223. <pre>type ErrCorrupted struct {
  224. Size <a href="../../../../../builtin/index.html#int">int</a>
  225. Reason <a href="../../../../../builtin/index.html#string">string</a>
  226. }</pre>
  227. <p>
  228. ErrCorrupted is the error type that generated by corrupted block or chunk.
  229. </p>
  230. <h3 id="ErrCorrupted.Error">func (*ErrCorrupted) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=3618:3655#L103">Error</a></h3>
  231. <pre>func (e *<a href="index.html#ErrCorrupted">ErrCorrupted</a>) Error() <a href="../../../../../builtin/index.html#string">string</a></pre>
  232. <h2 id="Reader">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=3999:4660#L114">Reader</a></h2>
  233. <pre>type Reader struct {
  234. <span class="comment">// contains filtered or unexported fields</span>
  235. }</pre>
  236. <p>
  237. Reader reads journals from an underlying io.Reader.
  238. </p>
  239. <h3 id="NewReader">func <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=4820:4895#L142">NewReader</a></h3>
  240. <pre>func NewReader(r <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Reader">Reader</a>, dropper <a href="index.html#Dropper">Dropper</a>, strict, checksum <a href="../../../../../builtin/index.html#bool">bool</a>) *<a href="index.html#Reader">Reader</a></pre>
  241. <p>
  242. NewReader returns a new reader. The dropper may be nil, and if
  243. strict is true then corrupted or invalid chunk will halt the journal
  244. reader entirely.
  245. </p>
  246. <h3 id="Reader.Next">func (*Reader) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=7607:7649#L238">Next</a></h3>
  247. <pre>func (r *<a href="index.html#Reader">Reader</a>) Next() (<a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Reader">Reader</a>, <a href="../../../../../builtin/index.html#error">error</a>)</pre>
  248. <p>
  249. Next returns a reader for the next journal. It returns io.EOF if there are no
  250. more journals. The reader returned becomes stale after the next Next call,
  251. and should no longer be used. If strict is false, the reader will returns
  252. io.ErrUnexpectedEOF error when found corrupted journal.
  253. </p>
  254. <h3 id="Reader.Reset">func (*Reader) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=7987:8073#L256">Reset</a></h3>
  255. <pre>func (r *<a href="index.html#Reader">Reader</a>) Reset(reader <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Reader">Reader</a>, dropper <a href="index.html#Dropper">Dropper</a>, strict, checksum <a href="../../../../../builtin/index.html#bool">bool</a>) <a href="../../../../../builtin/index.html#error">error</a></pre>
  256. <p>
  257. Reset resets the journal reader, allows reuse of the journal reader. Reset returns
  258. last accumulated error.
  259. </p>
  260. <h2 id="Writer">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=9292:9945#L334">Writer</a></h2>
  261. <pre>type Writer struct {
  262. <span class="comment">// contains filtered or unexported fields</span>
  263. }</pre>
  264. <p>
  265. Writer writes journals to an underlying io.Writer.
  266. </p>
  267. <h3 id="NewWriter">func <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=9982:10017#L358">NewWriter</a></h3>
  268. <pre>func NewWriter(w <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Writer">Writer</a>) *<a href="index.html#Writer">Writer</a></pre>
  269. <p>
  270. NewWriter returns a new Writer.
  271. </p>
  272. <h3 id="Writer.Close">func (*Writer) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=11240:11270#L412">Close</a></h3>
  273. <pre>func (w *<a href="index.html#Writer">Writer</a>) Close() <a href="../../../../../builtin/index.html#error">error</a></pre>
  274. <p>
  275. Close finishes the current journal and closes the writer.
  276. </p>
  277. <h3 id="Writer.Flush">func (*Writer) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=11550:11580#L424">Flush</a></h3>
  278. <pre>func (w *<a href="index.html#Writer">Writer</a>) Flush() <a href="../../../../../builtin/index.html#error">error</a></pre>
  279. <p>
  280. Flush finishes the current journal, writes to the underlying writer, and
  281. flushes it if that writer implements interface{ Flush() error }.
  282. </p>
  283. <h3 id="Writer.Next">func (*Writer) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=12261:12303#L458">Next</a></h3>
  284. <pre>func (w *<a href="index.html#Writer">Writer</a>) Next() (<a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Writer">Writer</a>, <a href="../../../../../builtin/index.html#error">error</a>)</pre>
  285. <p>
  286. Next returns a writer for the next journal. The writer returned becomes stale
  287. after the next Close, Flush or Next call, and should no longer be used.
  288. </p>
  289. <h3 id="Writer.Reset">func (*Writer) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/journal/journal.go?s=11852:11904#L439">Reset</a></h3>
  290. <pre>func (w *<a href="index.html#Writer">Writer</a>) Reset(writer <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Writer">Writer</a>) (err <a href="../../../../../builtin/index.html#error">error</a>)</pre>
  291. <p>
  292. Reset resets the journal writer, allows reuse of the journal writer. Reset
  293. will also closes the journal writer if not already.
  294. </p>
  295. <div id="footer">
  296. Build version go1.6.<br>
  297. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  298. the content of this page is licensed under the
  299. Creative Commons Attribution 3.0 License,
  300. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  301. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  302. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  303. </div>
  304. </div><!-- .container -->
  305. </div><!-- #page -->
  306. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  307. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.js"></script>
  308. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.js"></script>
  309. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  310. <script type="text/javascript" src="../../../../../../lib/godoc/godocs.js"></script>
  311. </body>
  312. </html>