@@ -105,7 +105,8 @@ const WS_COMMAND = {
105105 GET_WINDOWS_DRIVES : "getWinDrives" ,
106106 READ_DIR : "readDir" ,
107107 STAT : "stat" ,
108- READ_BIN_FILE : "readBinFile"
108+ READ_BIN_FILE : "readBinFile" ,
109+ WRITE_BIN_FILE : "writeBinFile"
109110} ;
110111
111112const LARGE_DATA_THRESHOLD = 2 * 1024 * 1024 ; // 2MB
@@ -220,6 +221,21 @@ function _readBinaryFile(ws, metadata) {
220221 } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to read file at path ${ fullPath } ` ) ) ;
221222}
222223
224+ /**
225+ *
226+ * @param ws
227+ * @param metadata
228+ * @param dataBuffer {ArrayBuffer}
229+ * @private
230+ */
231+ function _writeBinaryFile ( ws , metadata , dataBuffer ) {
232+ const fullPath = metadata . data . path ;
233+ fs . writeFile ( fullPath , Buffer . from ( dataBuffer ) )
234+ . then ( ( ) => {
235+ _sendResponse ( ws , metadata ) ;
236+ } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to write file at path ${ fullPath } ` ) ) ;
237+ }
238+
223239function processWSCommand ( ws , metadata , dataBuffer ) {
224240 try {
225241 switch ( metadata . commandCode ) {
@@ -241,6 +257,9 @@ function processWSCommand(ws, metadata, dataBuffer) {
241257 case WS_COMMAND . READ_BIN_FILE :
242258 _readBinaryFile ( ws , metadata ) ;
243259 return ;
260+ case WS_COMMAND . WRITE_BIN_FILE :
261+ _writeBinaryFile ( ws , metadata , dataBuffer ) ;
262+ return ;
244263 case WS_COMMAND . LARGE_DATA_SOCKET_ANNOUNCE :
245264 console . log ( "Large Data Transfer Socket established, socket Group: " , metadata . socketGroupID ) ;
246265 ws . isLargeData = true ;
0 commit comments