File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1515
1616import { assert } from 'chai'
1717import { getClient , randomString } from "./test-helper"
18+ import * as fs from "fs" ;
1819
1920
2021declare const describe , it ;
@@ -188,6 +189,31 @@ describe('Test for GET and PUT binary data', function () {
188189 } ) ;
189190} ) ;
190191
192+ describe ( "Test for PUT and GET streams" , function ( ) {
193+ this . timeout ( 10 * 1000 ) ;
194+ beforeEach ( ( done ) => {
195+ setTimeout ( function ( ) {
196+ done ( ) ;
197+ } , 1000 ) ;
198+ } ) ;
199+ const imageFileName = `stream-image-${ randomString ( ) } .png` ;
200+ it ( "Uploading drive item as a stream" , ( done ) => {
201+ let stream = fs . createReadStream ( './sample.png' ) ;
202+ return getClient ( ) . api ( `/me/drive/root/children/${ imageFileName } /content` ) . putStream ( stream , ( err ) => {
203+ assert . isTrue ( err === null ) ;
204+ done ( ) ;
205+ } ) ;
206+ } ) ;
207+
208+ it ( "GET drive item as a stream" , ( done ) => {
209+ return getClient ( ) . api ( `/me/drive/root:${ imageFileName } :/content` ) . getStream ( ( err , stream ) => {
210+ let writeStream = fs . createWriteStream ( `./${ imageFileName } ` ) ;
211+ stream . pipe ( writeStream ) . on ( 'error' , assert . fail ) ;
212+ done ( ) ;
213+ } )
214+ } ) ;
215+ } ) ;
216+
191217
192218
193219
You can’t perform that action at this time.
0 commit comments