Skip to content

Commit e3325f5

Browse files
committed
Added createFromFile & createFromBuffer to blob js
1 parent 4c48b11 commit e3325f5

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

lib/blob.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Blob.prototype.lookup = function(oid, callback) {
3232
/**
3333
* @callback Blob~lookupCallback Callback executed on lookup completion.
3434
* @param {GitError|null} error An Error or null if successful.
35-
* @param {Blob|null} blob The populated blob object or null.
35+
* @param {Blob|null} blob Retrieved blob object or null.
3636
*/
3737
var self = this;
3838
self.rawBlob.lookup(self.rawRepo, oid, function blobLookup(error, rawBlob) {
@@ -79,4 +79,46 @@ Blob.prototype.content = function(callback) {
7979
});
8080
};
8181

82+
/**
83+
* Create a new blob from the file at the given path.
84+
*
85+
* @param {String} path Full path to the file.
86+
* @param {Blob~createFromFileCallback} callback
87+
*/
88+
Blob.prototype.createFromFile = function(path, callback) {
89+
/**
90+
* @callback Blob~createFromFileCallback Callback executed after blob is created.
91+
* @param {GitError|null} error An Error or null if successful.
92+
* @param {Blob|null} content The new blob or null.
93+
*/
94+
var self = this;
95+
self.rawBlob.createFromFile(path, self.rawRepo, function blobCreateFromFileCallback(error, rawBlob) {
96+
if (success(error, callback)) {
97+
self.rawBlob = rawBlob;
98+
callback(null, self);
99+
}
100+
});
101+
};
102+
103+
/**
104+
* Create a new blob from the given buffer.
105+
*
106+
* @param {Buffer} buffer Buffer used to create blob.
107+
* @param {Blob~createFromBufferCallback} callback
108+
*/
109+
Blob.prototype.createFromFile = function(path, callback) {
110+
/**
111+
* @callback Blob~createFromBufferCallback Callback executed after blob is created.
112+
* @param {GitError|null} error An Error or null if successful.
113+
* @param {Blob|null} content The new blob or null.
114+
*/
115+
var self = this;
116+
self.rawBlob.createFromBuffer(buffer, self.rawRepo, function blobCreateFromBufferCallback(error, rawBlob) {
117+
if (success(error, callback)) {
118+
self.rawBlob = rawBlob;
119+
callback(null, self);
120+
}
121+
});
122+
};
123+
82124
exports.blob = Blob;

0 commit comments

Comments
 (0)