|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>Nodegit: Source: blob.js</title> |
| 6 | + |
| 7 | + <script src="scripts/prettify/prettify.js"> </script> |
| 8 | + <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | + <!--[if lt IE 9]> |
| 10 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | + <![endif]--> |
| 12 | + <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | + <link type="text/css" rel="stylesheet" href="styles/common.css"> |
| 14 | + <link type="text/css" rel="stylesheet" href="styles/ir_black.css"> |
| 15 | +</head> |
| 16 | + |
| 17 | +<body> |
| 18 | + |
| 19 | +<div id="main"> |
| 20 | + <!-- Fork Me --> |
| 21 | + <a href="http://github.com/tbranyen/nodegit"> |
| 22 | + <img class="forkme" |
| 23 | + src="http://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png" |
| 24 | + alt="Fork me on GitHub"> |
| 25 | + </a> |
| 26 | + |
| 27 | + <div id="container"> |
| 28 | + |
| 29 | + <!-- Branding --> |
| 30 | + <section class="branding"> |
| 31 | + <a class="download" href="http://github.com/tbranyen/nodegit/zipball/master"> |
| 32 | + <img src="http://github.com/images/modules/download/zip.png"> |
| 33 | + </a> |
| 34 | + <a class="download" href="http://github.com/tbranyen/nodegit/tarball/master"> |
| 35 | + <img src="http://github.com/images/modules/download/tar.png"> |
| 36 | + </a> |
| 37 | + <a href="http://github.com/tbranyen/nodegit">nodegit</a> |
| 38 | + <span class="small">by <a href="http://github.com/tbranyen">tbranyen</a> & <a href="http://github.com/faceleg">faceleg</a></span> |
| 39 | + </section> |
| 40 | + <div class="social"> |
| 41 | + <a href="https://travis-ci.org/tbranyen/nodegit"><img src="https://travis-ci.org/tbranyen/nodegit.png" alt="Build Status" style="max-width:100%;"></a> |
| 42 | + <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://nodegit.github.com/" data-text="When I need git tools in Node.js, I use nodegit" data-hashtags="nodejs">Tweet</a> |
| 43 | + <iframe src="http://ghbtns.com/github-btn.html?count=true&user=tbranyen&repo=nodegit&type=watch" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe> |
| 44 | + </div> |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + <section> |
| 51 | + <article> |
| 52 | + <pre class="prettyprint source"><code>var git = require('../'), |
| 53 | + success = require('./utilities').success; |
| 54 | + |
| 55 | +/** |
| 56 | + * Blob convenience class constructor. |
| 57 | + * |
| 58 | + * @constructor |
| 59 | + * @param {git.raw.Repo} rawRepo Raw repository object. |
| 60 | + * @param {git.raw.Blob} [rawBlob = new git.raw.Blob(rawRepo)] Raw blob object. |
| 61 | + */ |
| 62 | +var Blob = function(rawRepo, rawBlob) { |
| 63 | + if(!(rawRepo instanceof git.raw.Repo)) { |
| 64 | + throw new git.error('First parameter for Blob must be a raw repo'); |
| 65 | + } |
| 66 | + this.rawRepo = rawRepo; |
| 67 | + |
| 68 | + if(typeof rawBlob !== 'undefined' && |
| 69 | + rawBlob instanceof git.raw.Blob) { |
| 70 | + this.rawBlob = rawBlob; |
| 71 | + } else { |
| 72 | + this.rawBlob = new git.raw.Blob(this.rawRepo); |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | +/** |
| 77 | + * Retrieve the blob represented by the oid. |
| 78 | + * |
| 79 | + * @param {git.raw.Oid} oid The OID representing the blob to lookup. |
| 80 | + * @param {Blob~lookupCallback} callback |
| 81 | + */ |
| 82 | +Blob.prototype.lookup = function(oid, callback) { |
| 83 | + /** |
| 84 | + * @callback Blob~lookupCallback Callback executed on lookup completion. |
| 85 | + * @param {GitError|null} error An Error or null if successful. |
| 86 | + * @param {Blob|null} blob Retrieved blob object or null. |
| 87 | + */ |
| 88 | + var self = this; |
| 89 | + self.rawBlob.lookup(self.rawRepo, oid, function blobLookup(error, rawBlob) { |
| 90 | + if (success(error, callback)) { |
| 91 | + self.rawBlob = rawBlob; |
| 92 | + callback(null, self); |
| 93 | + } |
| 94 | + }); |
| 95 | +}; |
| 96 | + |
| 97 | +/** |
| 98 | + * Retrieve the blob's raw content buffer. |
| 99 | + * |
| 100 | + * @param {Blob~rawContentCallback} callback |
| 101 | + */ |
| 102 | +Blob.prototype.rawContent = function(callback) { |
| 103 | + /** |
| 104 | + * @callback Blob~rawContentCallback Callback executed after raw content is retrieved. |
| 105 | + * @param {GitError|null} error An Error or null if successful. |
| 106 | + * @param {Buffer|null} content The raw content of the blob or null. |
| 107 | + */ |
| 108 | + this.rawBlob.rawContent(function(error, content) { |
| 109 | + if (success(error, callback)) { |
| 110 | + callback(null, content); |
| 111 | + } |
| 112 | + }); |
| 113 | +}; |
| 114 | + |
| 115 | +/** |
| 116 | + * Retrieve the blob's content. |
| 117 | + * |
| 118 | + * @param {Blob~contentCallback} callback |
| 119 | + */ |
| 120 | +Blob.prototype.content = function(callback) { |
| 121 | + /** |
| 122 | + * @callback Blob~contentCallback Callback executed after content is retrieved. |
| 123 | + * @param {GitError|null} error An Error or null if successful. |
| 124 | + * @param {String|null} content The content of the blob or null. |
| 125 | + */ |
| 126 | + this.rawContent(function(error, content) { |
| 127 | + if (success(error, callback)) { |
| 128 | + callback(null, content.toString()); |
| 129 | + } |
| 130 | + }); |
| 131 | +}; |
| 132 | + |
| 133 | +/** |
| 134 | + * Create a new blob from the file at the given path. |
| 135 | + * |
| 136 | + * @param {String} path Full path to the file. |
| 137 | + * @param {Blob~createFromFileCallback} callback |
| 138 | + */ |
| 139 | +Blob.prototype.createFromFile = function(path, callback) { |
| 140 | + /** |
| 141 | + * @callback Blob~createFromFileCallback Callback executed after blob is created. |
| 142 | + * @param {GitError|null} error An Error or null if successful. |
| 143 | + * @param {Blob|null} blob The new blob or null. |
| 144 | + */ |
| 145 | + var self = this; |
| 146 | + self.rawBlob.createFromFile(path, self.rawRepo, function blobCreateFromFileCallback(error, rawBlob) { |
| 147 | + if (success(error, callback)) { |
| 148 | + self.rawBlob = rawBlob; |
| 149 | + callback(null, self); |
| 150 | + } |
| 151 | + }); |
| 152 | +}; |
| 153 | + |
| 154 | +/** |
| 155 | + * Create a new blob from the given buffer. |
| 156 | + * |
| 157 | + * @param {Buffer} buffer Buffer used to create blob. |
| 158 | + * @param {Blob~createFromBufferCallback} callback |
| 159 | + */ |
| 160 | +Blob.prototype.createFromFile = function(path, callback) { |
| 161 | + /** |
| 162 | + * @callback Blob~createFromBufferCallback Callback executed after blob is created. |
| 163 | + * @param {GitError|null} error An Error or null if successful. |
| 164 | + * @param {Blob|null} content The new blob or null. |
| 165 | + */ |
| 166 | + var self = this; |
| 167 | + self.rawBlob.createFromBuffer(buffer, self.rawRepo, function blobCreateFromBufferCallback(error, rawBlob) { |
| 168 | + if (success(error, callback)) { |
| 169 | + self.rawBlob = rawBlob; |
| 170 | + callback(null, self); |
| 171 | + } |
| 172 | + }); |
| 173 | +}; |
| 174 | + |
| 175 | +exports.blob = Blob; |
| 176 | +</code></pre> |
| 177 | + </article> |
| 178 | + </section> |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + </div> |
| 184 | +</div> |
| 185 | + |
| 186 | +<nav> |
| 187 | + <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="Blob.html">Blob</a></li><li><a href="Commit.html">Commit</a></li><li><a href="GitError.html">GitError</a></li><li><a href="Oid.html">Oid</a></li><li><a href="Reference.html">Reference</a></li><li><a href="Repo.html">Repo</a></li><li><a href="RevWalk.html">RevWalk</a></li><li><a href="Tree.html">Tree</a></li><li><a href="TreeEntry.html">TreeEntry</a></li></ul><h3>Events</h3><ul><li><a href="Commit.html#event:commit">commit</a></li><li><a href="Commit.html#event:end">end</a></li><li><a href="Tree.html#event:end">end</a></li><li><a href="Tree.html#event:entry">entry</a></li></ul><h3>Namespaces</h3><ul><li><a href="utilities.html">utilities</a></li></ul><h3>Global</h3><ul><li><a href="global.html#repo">repo</a></li></ul> |
| 188 | +</nav> |
| 189 | + |
| 190 | +<br clear="both"> |
| 191 | + |
| 192 | +<footer> |
| 193 | + <div class="built-in"> |
| 194 | + <a target="_blank" href="http://bostonbuilt.org"><img class="boston" src="img/boston.gif" alt="Built in Boston USA"></a> |
| 195 | + <span class="amp">&</span> |
| 196 | + <img class="nz" src="img/nz.png" alt="Built NZ" /> |
| 197 | + </div> |
| 198 | +</footer> |
| 199 | + |
| 200 | +<script> prettyPrint(); </script> |
| 201 | +<script src="scripts/highlight.pack.js"></script> |
| 202 | +<script> |
| 203 | + hljs.tabReplace = ' '; |
| 204 | + hljs.initHighlightingOnLoad(); |
| 205 | +</script> |
| 206 | +<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> |
| 207 | +</body> |
| 208 | +</html> |
| 209 | + |
| 210 | +<!-- |
| 211 | + ____ ____ ____ ____ ____ ____ ____ |
| 212 | + ||N |||O |||D |||E |||. |||J |||S || |
| 213 | + ||__|||__|||__|||__|||__|||__|||__|| |
| 214 | + |/__\|/__\|/__\|/__\|/__\|/__\|/__\| |
| 215 | +
|
| 216 | + ____ |
| 217 | + ||+ || |
| 218 | + ||__|| |
| 219 | + |/__\| |
| 220 | +
|
| 221 | + ____ ____ ____ ____ ____ ____ ____ |
| 222 | + ||L |||I |||B |||G |||I |||T |||2 || |
| 223 | + ||__|||__|||__|||__|||__|||__|||__|| |
| 224 | + |/__\|/__\|/__\|/__\|/__\|/__\|/__\| |
| 225 | +
|
| 226 | + ____ |
| 227 | + ||= || |
| 228 | + ||__|| |
| 229 | + |/__\| |
| 230 | +
|
| 231 | + ____ ____ ____ ____ ____ ____ ____ |
| 232 | + ||O |||W |||N |||Z |||O |||N |||E || |
| 233 | + ||__|||__|||__|||__|||__|||__|||__|| |
| 234 | + |/__\|/__\|/__\|/__\|/__\|/__\|/__\| |
| 235 | +
|
| 236 | +--> |
0 commit comments