forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblob.js
More file actions
73 lines (65 loc) · 1.89 KB
/
blob.js
File metadata and controls
73 lines (65 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var util = require("util");
var NodeGit = require("../");
var Blob = NodeGit.Blob;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var TreeEntry = NodeGit.TreeEntry;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var _filteredContent = Blob.filteredContent;
var _filter = Blob.prototype.filter;
/**
* Retrieves the blob pointed to by the oid
* @async
* @param {Repository} repo The repo that the blob lives in
* @param {String|Oid|Blob} id The blob to lookup
* @return {Blob}
*/
Blob.lookup = LookupWrapper(Blob);
/**
* Retrieve the content of the Blob.
*
* @return {Buffer} Contents as a buffer.
*/
Blob.prototype.content = function() {
return this.rawcontent().toBuffer(this.rawsize());
};
/**
* Retrieve the Blob's type.
*
* @return {Number} The filemode of the blob.
*/
Blob.prototype.filemode = function() {
var FileMode = TreeEntry.FILEMODE;
return this.isBinary() ? FileMode.EXECUTABLE : FileMode.BLOB;
};
/**
* Retrieve the Blob's content as String.
*
* @return {String} Contents as a string.
*/
Blob.prototype.toString = function() {
return this.content().toString();
};
/**
* Get a buffer with the filtered content of a blob.
*
* This applies filters as if the blob was being checked out to the
* working directory under the specified filename. This may apply
* CRLF filtering or other types of changes depending on the file
* attributes set for the blob and the content detected in it.
*
* @async
* @param asPath Path used for file attribute lookups, etc.
* @param opts Options to use for filtering the blob
* @return {Promise<string>}
*/
Blob.prototype.filter = function(asPath, opts) {
if (opts) {
opts = normalizeOptions(opts, NodeGit.BlobFilterOptions);
}
return _filter.call(this, asPath, opts);
};
Blob.filteredContent = util.deprecate(
_filteredContent,
"NodeGit.Blob.filteredContent is deprecated" +
" use NodeGit.Blob.prototype.filter instead."
);