File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -475,6 +475,7 @@ class Device {
475475 * @param {{
476476 * onScanComplete: (files: string[]) => void,
477477 * onUpload: (file: string) => void,
478+ * transform: (id: string, body: string) => string
478479 * }} options
479480 */
480481 async upload ( source , destination , options ) {
@@ -492,7 +493,11 @@ class Device {
492493
493494 const _uploadFile = async ( file , destination ) => {
494495 this . log . traceShort ( "uploadFile" , file , "to" , destination ) ;
495- const data = Buffer . from ( readFileSync ( file ) ) ;
496+
497+ const data = options . transform
498+ ? Buffer . from ( options . transform ( file , readFileSync ( file , "utf-8" ) ) )
499+ : Buffer . from ( readFileSync ( file ) ) ;
500+
496501 return this . adapter . putFile ( destination , data , { checkIfSimilarBeforeUpload : true } ) ;
497502 } ;
498503
Original file line number Diff line number Diff line change @@ -622,8 +622,9 @@ class Commands {
622622 * @param {{fsPath: string} } uri the file/folder to upload
623623 * @param {import('../Device.js').Device } device
624624 * @param {string } destination not including the device.rootPath ( /flash or / )
625+ * @param {(id: string, body: string) => string= } transform transforms content of file during upload
625626 */
626- upload : async ( { fsPath } , device , destination ) => {
627+ upload : async ( { fsPath } , device , destination , transform ) => {
627628 const friendlySource = fsPath . replace ( / .* [ / \\ ] / g, "" ) ;
628629 if ( ! device . connected . get ( ) ) await device . connect ( ) ;
629630 try {
@@ -637,6 +638,7 @@ class Commands {
637638 message : `Uploading "${ file } " to "${ device . displayName } "...` ,
638639 increment : 100 / filesAmount ,
639640 } ) ,
641+ transform,
640642 } ) ;
641643 } ) ;
642644 } catch ( err ) {
You can’t perform that action at this time.
0 commit comments