From 9554d2a7f4dbe45f04a99ce849a30bf07c6e7e4a Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Thu, 2 Jul 2020 11:08:10 +0100 Subject: [PATCH] style(streaming): minor --- modules/core/rest/create.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/core/rest/create.js b/modules/core/rest/create.js index 9902e9b07..9cec6fd0f 100644 --- a/modules/core/rest/create.js +++ b/modules/core/rest/create.js @@ -61,6 +61,7 @@ module.exports = ( app ) => { // helper func to flush the gzip buffer const writeBuffer = ( ) => { + console.log( `writing buff ${currentChunkSize}` ) if ( simpleText ) { gzip.write( chunk ) } else { @@ -75,18 +76,17 @@ module.exports = ( app ) => { let obj = await getObject( req.params.objectId ) var objString = JSON.stringify( obj ) if ( simpleText ) { - chunk += `${obj.id} \t ${objString}\n` + chunk += `${obj.id}\t${objString}\n` } else { chunk.push( objString + ',' ) } - writeBuffer( ) dbStream.on( 'data', row => { let data = JSON.stringify( row.data ) currentChunkSize += Buffer.byteLength( data, 'utf8' ) if ( simpleText ) { - chunk += `${row.data.id} \t ${data}\n` + chunk += `${row.data.id}\t${data}\n` } else { chunk.push( data ) } @@ -103,10 +103,20 @@ module.exports = ( app ) => { if ( currentChunkSize !== 0 ) { writeBuffer( ) if ( !simpleText ) gzip.write( ']' ) - gzip.end( ) } + gzip.end( ) + console.log( 'written end' ) } ) gzip.pipe( res ) } ) + + app.get( '/objects/:streamId/:objectId/single', async ( req, res ) => { + + // TODO: authN & authZ checks + + let obj = await getObject( req.params.objectId ) + + res.send( obj ) + } ) } \ No newline at end of file