Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit24f9c28

Browse files
committed
Enable to pass an object to createBlob
createBlob automatically encodes string parameterby Utf8 library. In some cases the string valuecan be already encoded in Utf8 so the encodingshould be skipped.This commit enables to pass object containingthe content and encoding items. This object isdirectly sent to Github. Users have better controlabout what is actually sending.closes#463
1 parent64a9223 commit24f9c28

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

‎lib/Repository.js‎

Lines changed: 12 additions & 3 deletions
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+
}elseif(typeofcontent==='object'){
287+
log('content is an object');
288+
289+
if(typeofcontent.content!=='string'){
290+
thrownewError('The object must contain content item of type string.');
291+
}
292+
293+
returncontent;
294+
286295
}else{// eslint-disable-line
287296
log(`Not sure what this content is:${typeofcontent},${JSON.stringify(content)}`);
288-
thrownewError('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)');
297+
thrownewError('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web) or Object');
289298
}
290299
}
291300

‎test/repository.spec.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,16 @@ describe('Repository', function() {
578578
remoteRepo.createBlob(imageBlob,assertSuccessful(done));
579579
});
580580

581+
it('should read the same unicode string blob as it was written',function(done){
582+
letcontent='The temperature is 25°C'
583+
remoteRepo.createBlob({content:content,encoding:'utf-8'},assertSuccessful(done,function(_,resp){
584+
remoteRepo.getBlob(resp.sha,assertSuccessful(done,function(_,returnedContent){
585+
expect(returnedContent).to.be(content);
586+
done();
587+
}));
588+
}));
589+
});
590+
581591
it('should star the repo',function(done){
582592
remoteRepo.star(assertSuccessful(done,function(){
583593
remoteRepo.isStarred(assertSuccessful(done));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp