Skip to content

Commit b34e192

Browse files
committed
Enable to pass an object to createBlob
createBlob automatically encodes string parameter by Utf8 library. In some cases the string value can be already encoded in Utf8 so the encoding should be skipped. This commit enables to pass object containing the content and encoding items. This object is directly sent to Github. Users have better control about what is actually sending. closes github-tools#463
1 parent 22b889c commit b34e192

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/Repository.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Repository extends Requestable {
245245
/**
246246
* Create a blob
247247
* @see https://developer.github.com/v3/git/blobs/#create-a-blob
248-
* @param {(string|Buffer|Blob)} content - the content to add to the repository
248+
* @param {(string|Buffer|Blob|Object)} content - the content to add to the repository
249249
* @param {Requestable.callback} cb - will receive the details of the created blob
250250
* @return {Promise} - the promise for the http request
251251
*/
@@ -258,7 +258,7 @@ class Repository extends Requestable {
258258

259259
/**
260260
* Get the object that represents the provided content
261-
* @param {string|Buffer|Blob} content - the content to send to the server
261+
* @param {string|Buffer|Blob|Object} content - the content to send to the server
262262
* @return {Object} the representation of `content` for the GitHub API
263263
*/
264264
_getContentObject(content) {
@@ -283,9 +283,18 @@ class Repository extends Requestable {
283283
encoding: 'base64',
284284
};
285285

286+
} else if (typeof content === 'object') {
287+
log('content is an object');
288+
289+
if (typeof content.content !== 'string') {
290+
throw new Error('The object must contain content item of type string.')
291+
}
292+
293+
return content;
294+
286295
} else { // eslint-disable-line
287296
log(`Not sure what this content is: ${typeof content}, ${JSON.stringify(content)}`);
288-
throw new Error('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)');
297+
throw new Error('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web) or Object');
289298
}
290299
}
291300

0 commit comments

Comments
 (0)