Skip to content

Commit

Permalink
feat: append service, provides backend functionality towards #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Bowe committed Aug 24, 2021
1 parent 14b1269 commit 7ba0b63
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "ISC",
"dependencies": {
"@sasjs/adapter": "^2.10.0",
"@sasjs/core": "^2.39.0"
"@sasjs/core": "^2.41.0"
},
"devDependencies": {
"cpy-t": "^1.1.5"
Expand Down
46 changes: 46 additions & 0 deletions sasjs/services/common/append.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
@file
@brief appends a file from frontend to a user provided location
@details Returns the file size or -1 in case of error.
<h4> SAS Macros </h4>
@li mf_getfilesize.sas
@li mf_isdir.sas
@li mp_abort.sas
@li mp_binarycopy.sas
**/

%mp_abort(iftrue= (%mf_isdir(&path) = 0)
,mac=&_program..sas
,msg=%str(File path (&path) is not a valid directory)
)

/*
Grab the file uri. IF there are multiple, they are numbered, so
placeholder logic is provided for convenience.
*/
%global _webin_fileuri _webin_fileuri1 _webin_filename _webin_filename1;
%let infile=%sysfunc(coalescec(&_webin_fileuri1,&_webin_fileuri));
%let outfile=%sysfunc(coalescec(&_webin_filename1,&_webin_filename));

/* read in the file from the file service */
filename filein filesrvc "&infile";
filename fileout "&path/&outfile";

%mp_binarycopy(inref=filein, outref=fileout, mode=APPEND)

%mp_abort(iftrue= (&syscc ge 4)
,mac=&_program..sas
,msg=%str(Error occurred whilst reading &infile and writing to &outfile )
)

/* success - lets create a directory listing */
data fromsas;
filesize="%mf_getfilesize(fpath=&path/&outfile,format=yes)";
run;

/* now send it back to the frontend */
%webout(OPEN)
%webout(OBJ,fromsas)
%webout(CLOSE)

0 comments on commit 7ba0b63

Please sign in to comment.