Skip to content

Commit 4029dfa

Browse files
committed
Callback is now called when write stream completes
1 parent 3d573bf commit 4029dfa

6 files changed

Lines changed: 35 additions & 10 deletions

File tree

lib/graph-js-sdk-web.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,20 @@ class GraphRequest {
234234
}
235235
});
236236
}
237-
put(stream, errorCallback) {
237+
put(stream, callback) {
238238
this.config.authProvider((err, accessToken) => {
239239
if (err === null && accessToken !== null) {
240240
let url = this.buildFullUrl();
241241
let req = this.configureRequest(request.put(url), accessToken);
242242
req.type('application/octet-stream');
243-
stream.pipe(req).on('error', errorCallback);
243+
stream
244+
.pipe(req)
245+
.on('error', function (err) {
246+
callback(err, null);
247+
})
248+
.on('end', function () {
249+
callback(null);
250+
});
244251
}
245252
});
246253
}

lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export declare class GraphRequest {
6363
private routeResponseToCallback(requestBuilder, callback);
6464
private sendRequestAndRouteResponse(requestBuilder, callback?);
6565
getStream(callback: GraphRequestCallback): void;
66-
put(stream: any, errorCallback: Function): void;
66+
put(stream: any, callback: Function): void;
6767
private configureRequest(requestBuilder, accessToken);
6868
getResultIterator(): IterableIterator<(callback: any) => void>;
6969
query(queryDictionaryOrString: string | {

lib/index.js

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/node/node-sample.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,14 @@ client
272272
});
273273

274274
// Update my photo
275-
let profilePhotoReadStream = fs.createReadStream('../me.jpg');
275+
let fs = require('fs');
276+
let profilePhotoReadStream = fs.createReadStream('me.jpg');
276277

277278
client
278279
.api('/me/photo/$value')
279280
.put(profilePhotoReadStream, (err) => {
280-
console.log(err);
281+
if (err) {
282+
console.log(err);
283+
return;
284+
}
281285
});

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,20 @@ export class GraphRequest {
361361
});
362362
}
363363

364-
put(stream:any, errorCallback:Function) {
364+
put(stream:any, callback:Function) {
365365
this.config.authProvider((err, accessToken) => {
366366
if (err === null && accessToken !== null) {
367367
let url = this.buildFullUrl();
368368
let req:request.Request = this.configureRequest(request.put(url), accessToken);
369369
req.type('application/octet-stream');
370-
stream.pipe(req).on('error', errorCallback);
370+
stream
371+
.pipe(req)
372+
.on('error', function(err) {
373+
callback(err, null)
374+
})
375+
.on('end', function() {
376+
callback(null)
377+
});
371378
}
372379
});
373380
}

0 commit comments

Comments
 (0)