File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -74,10 +74,21 @@ class CommandEdit extends CommandPolykey {
7474 metadata : auth ,
7575 } ) ;
7676 await writer . close ( ) ;
77- let rawSecretContent : string = '' ;
77+ let fileWriter : fs . WriteStream | undefined = undefined ;
7878 for await ( const chunk of response . readable ) {
7979 if ( chunk . type === 'SuccessMessage' ) {
80- rawSecretContent += chunk . secretContent ;
80+ // Only create the file if we are getting data
81+ if ( fileWriter == null ) {
82+ fileWriter = fs . createWriteStream ( tmpFile , { flags : 'a' } ) ;
83+ }
84+ // Wait for the internal buffer to drain if it is full
85+ if (
86+ ! fileWriter . write ( Buffer . from ( chunk . secretContent , 'binary' ) )
87+ ) {
88+ await new Promise ( ( resolve ) =>
89+ fileWriter ! . once ( 'drain' , resolve ) ,
90+ ) ;
91+ }
8192 } else {
8293 if ( chunk . code === 'ENOENT' ) {
8394 exists = false ;
@@ -101,12 +112,8 @@ class CommandEdit extends CommandPolykey {
101112 }
102113 }
103114 }
104- // Only make the temp file is the secret actually exists
105- if ( exists ) {
106- const secretContent = Buffer . from ( rawSecretContent , 'binary' ) ;
107- await this . fs . promises . writeFile ( tmpFile , secretContent ) ;
108- return exists ;
109- }
115+ if ( fileWriter != null ) fileWriter . end ( ) ;
116+ return exists ;
110117 } ,
111118 meta ,
112119 ) ;
You can’t perform that action at this time.
0 commit comments