File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,50 @@ pub(crate) fn create_base64_proxy(_realm: &QuickJsRealmAdapter) -> JsProxy {
117
117
)
118
118
}
119
119
} )
120
+ . static_method ( "decodeString" , |_runtime, realm, args| {
121
+ // todo async
122
+
123
+ if args. is_empty ( ) || !args[ 0 ] . is_string ( ) {
124
+ Err ( JsError :: new_str ( "decodeString expects a single string arg" ) )
125
+ } else {
126
+ let s = args[ 0 ] . to_string ( ) ?;
127
+ realm. create_resolving_promise (
128
+ move || {
129
+ let engine = base64:: engine:: general_purpose:: STANDARD ;
130
+ let decoded = engine
131
+ . decode ( s)
132
+ . map_err ( |e| JsError :: new_string ( format ! ( "{e}" ) ) ) ?;
133
+ let s = String :: from_utf8_lossy ( & decoded) ;
134
+ Ok ( s. to_string ( ) )
135
+ } ,
136
+ |realm, p_res| {
137
+ //
138
+ realm. create_string ( p_res. as_str ( ) )
139
+ } ,
140
+ )
141
+ }
142
+ } )
143
+ . static_method ( "decodeStringSync" , |_runtime, realm, args| {
144
+ if args. is_empty ( ) || !args[ 0 ] . is_string ( ) {
145
+ Err ( JsError :: new_str ( "decodeString expects a single string arg" ) )
146
+ } else {
147
+ let s = args[ 0 ] . to_string ( ) ?;
148
+ realm. create_resolving_promise (
149
+ move || {
150
+ let engine = base64:: engine:: general_purpose:: STANDARD ;
151
+ let decoded = engine
152
+ . decode ( s)
153
+ . map_err ( |e| JsError :: new_string ( format ! ( "{e}" ) ) ) ?;
154
+ let s = String :: from_utf8_lossy ( & decoded) ;
155
+ Ok ( s. to_string ( ) )
156
+ } ,
157
+ |realm, p_res| {
158
+ //
159
+ realm. create_string ( p_res. as_str ( ) )
160
+ } ,
161
+ )
162
+ }
163
+ } )
120
164
. static_method ( "decodeSync" , |_runtime, realm, args| {
121
165
// todo async
122
166
You can’t perform that action at this time.
0 commit comments