@sasjs/core 4.20.0 → 4.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  @file
3
3
  @brief Streams a file to _webout according to content type
4
- @details Will set headers using appropriate functions (SAS 9 vs Viya) and send
5
- content as a binary stream.
4
+ @details Will set headers using appropriate functions per the server type
5
+ (Viya, EBI, [SASjs Server](https://github.com/sasjs/server)) and stream
6
+ content using mp_binarycopy().
6
7
 
7
8
  Usage:
8
9
 
@@ -12,7 +13,14 @@
12
13
 
13
14
  %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt)
14
15
 
15
- @param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL
16
+ @param [in] contenttype= (TEXT) Supported:
17
+ @li CSV
18
+ @li EXCEL
19
+ @li MARKDOWN
20
+ @li TEXT
21
+ @li ZIP
22
+ Feel free to submit PRs to support more mime types! The official list is
23
+ here: https://www.iana.org/assignments/media-types/media-types.xhtml
16
24
  @param [in] inloc= /path/to/file.ext to be sent
17
25
  @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`)
18
26
  @param [in] iftrue= (1=1) Provide a condition under which to execute.
@@ -58,7 +66,7 @@ run;
58
66
  %if &contentype=CSV %then %do;
59
67
  %if (&platform=SASMETA and &streamweb=1) %then %do;
60
68
  data _null_;
61
- rc=stpsrv_header('Content-type','application/csv');
69
+ rc=stpsrv_header('Content-Type','application/csv');
62
70
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
63
71
  run;
64
72
  %end;
@@ -68,7 +76,7 @@ run;
68
76
  contentdisp="attachment; filename=&outname";
69
77
  %end;
70
78
  %else %if &platform=SASJS %then %do;
71
- %mfs_httpheader(Content-type,application/csv)
79
+ %mfs_httpheader(Content-Type,application/csv)
72
80
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
73
81
  %end;
74
82
  %end;
@@ -76,7 +84,7 @@ run;
76
84
  /* suitable for XLS format */
77
85
  %if (&platform=SASMETA and &streamweb=1) %then %do;
78
86
  data _null_;
79
- rc=stpsrv_header('Content-type','application/vnd.ms-excel');
87
+ rc=stpsrv_header('Content-Type','application/vnd.ms-excel');
80
88
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
81
89
  run;
82
90
  %end;
@@ -86,14 +94,14 @@ run;
86
94
  contentdisp="attachment; filename=&outname";
87
95
  %end;
88
96
  %else %if &platform=SASJS %then %do;
89
- %mfs_httpheader(Content-type,application/vnd.ms-excel)
97
+ %mfs_httpheader(Content-Type,application/vnd.ms-excel)
90
98
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
91
99
  %end;
92
100
  %end;
93
101
  %else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
94
102
  %if (&platform=SASMETA and &streamweb=1) %then %do;
95
103
  data _null_;
96
- rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
104
+ rc=stpsrv_header('Content-Type',"image/%lowcase(&contenttype)");
97
105
  run;
98
106
  %end;
99
107
  %else %if &platform=SASVIYA %then %do;
@@ -101,30 +109,30 @@ run;
101
109
  contenttype="image/%lowcase(&contenttype)";
102
110
  %end;
103
111
  %else %if &platform=SASJS %then %do;
104
- %mfs_httpheader(Content-type,image/%lowcase(&contenttype))
112
+ %mfs_httpheader(Content-Type,image/%lowcase(&contenttype))
105
113
  %end;
106
114
  %end;
107
- %else %if &contentype=HTML %then %do;
115
+ %else %if &contentype=HTML or &contenttype=MARKDOWN %then %do;
108
116
  %if (&platform=SASMETA and &streamweb=1) %then %do;
109
117
  data _null_;
110
- rc=stpsrv_header('Content-type','text/html');
118
+ rc=stpsrv_header('Content-Type',"text/%lowcase(&contenttype)");
111
119
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
112
120
  run;
113
121
  %end;
114
122
  %else %if &platform=SASVIYA %then %do;
115
123
  filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
116
- contenttype="text/html"
124
+ contenttype="text/%lowcase(&contenttype)"
117
125
  contentdisp="attachment; filename=&outname";
118
126
  %end;
119
127
  %else %if &platform=SASJS %then %do;
120
- %mfs_httpheader(Content-type,text/html)
128
+ %mfs_httpheader(Content-Type,text/%lowcase(&contenttype))
121
129
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
122
130
  %end;
123
131
  %end;
124
132
  %else %if &contentype=TEXT %then %do;
125
133
  %if (&platform=SASMETA and &streamweb=1) %then %do;
126
134
  data _null_;
127
- rc=stpsrv_header('Content-type','application/text');
135
+ rc=stpsrv_header('Content-Type','application/text');
128
136
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
129
137
  run;
130
138
  %end;
@@ -134,14 +142,14 @@ run;
134
142
  contentdisp="attachment; filename=&outname";
135
143
  %end;
136
144
  %else %if &platform=SASJS %then %do;
137
- %mfs_httpheader(Content-type,application/text)
145
+ %mfs_httpheader(Content-Type,application/text)
138
146
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
139
147
  %end;
140
148
  %end;
141
149
  %else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
142
150
  %if (&platform=SASMETA and &streamweb=1) %then %do;
143
151
  data _null_;
144
- rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)");
152
+ rc=stpsrv_header('Content-Type',"font/%lowcase(&contenttype)");
145
153
  run;
146
154
  %end;
147
155
  %else %if &platform=SASVIYA %then %do;
@@ -149,13 +157,13 @@ run;
149
157
  contenttype="font/%lowcase(&contenttype)";
150
158
  %end;
151
159
  %else %if &platform=SASJS %then %do;
152
- %mfs_httpheader(Content-type,font/%lowcase(&contenttype))
160
+ %mfs_httpheader(Content-Type,font/%lowcase(&contenttype))
153
161
  %end;
154
162
  %end;
155
163
  %else %if &contentype=XLSX %then %do;
156
164
  %if (&platform=SASMETA and &streamweb=1) %then %do;
157
165
  data _null_;
158
- rc=stpsrv_header('Content-type',
166
+ rc=stpsrv_header('Content-Type',
159
167
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
160
168
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
161
169
  run;
@@ -167,7 +175,7 @@ run;
167
175
  contentdisp="attachment; filename=&outname";
168
176
  %end;
169
177
  %else %if &platform=SASJS %then %do;
170
- %mfs_httpheader(Content-type
178
+ %mfs_httpheader(Content-Type
171
179
  ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
172
180
  )
173
181
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
@@ -176,7 +184,7 @@ run;
176
184
  %else %if &contentype=ZIP %then %do;
177
185
  %if (&platform=SASMETA and &streamweb=1) %then %do;
178
186
  data _null_;
179
- rc=stpsrv_header('Content-type','application/zip');
187
+ rc=stpsrv_header('Content-Type','application/zip');
180
188
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
181
189
  run;
182
190
  %end;
@@ -186,7 +194,7 @@ run;
186
194
  contentdisp="attachment; filename=&outname";
187
195
  %end;
188
196
  %else %if &platform=SASJS %then %do;
189
- %mfs_httpheader(Content-type,application/zip)
197
+ %mfs_httpheader(Content-Type,application/zip)
190
198
  %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
191
199
  %end;
192
200
  %end;
@@ -287,9 +287,11 @@ filename &webref "&webrefpath";
287
287
  %end;
288
288
 
289
289
  %if &mdebug=0 %then %do;
290
- filename &webref clear;
291
290
  filename &fref1 clear;
292
- filename &fref2 clear;
291
+ %if &platform ne SASJS %then %do;
292
+ filename &fref2 clear;
293
+ filename &webref clear;
294
+ %end;
293
295
  %end;
294
296
  %else %do;
295
297
  %put &sysmacroname exit vars:;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.20.0"
38
+ "version": "4.21.1"
39
39
  }
@@ -59,7 +59,7 @@
59
59
  outref=0,
60
60
  outlogds=_null_
61
61
  )/*/STORE SOURCE*/;
62
- %local dbg fref1 chopout1 chopout2;
62
+ %local dbg i var ds1 fref1 chopout1 chopout2;
63
63
  %if &mdebug=1 %then %do;
64
64
  %put &sysmacroname entry vars:;
65
65
  %put _local_;
@@ -82,13 +82,15 @@
82
82
  %let ds1=%mf_getuniquename();
83
83
  data &ds1;
84
84
  length fileref $8 name $32 filename $256 var $300;
85
- webcount=countw("&inputfiles");
86
- do i=1 to webcount;
87
- var=scan("&inputfiles",i,' ');
88
- fileref=scan(var,1,':');
89
- name=scan(var,2,':');
90
- filename=cats(name,'.csv');
91
- output;
85
+ if "&inputfiles" ne "0" then do;
86
+ webcount=countw("&inputfiles");
87
+ do i=1 to webcount;
88
+ var=scan("&inputfiles",i,' ');
89
+ fileref=scan(var,1,':');
90
+ name=scan(var,2,':');
91
+ filename=cats(name,'.csv');
92
+ output;
93
+ end;
92
94
  end;
93
95
  run;
94
96