-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
port: Better binary data support in Expression/LG functions #3390
Conversation
Additional change: Migrate all |
Another question:
But in node >= 11 and browser(> IE 11), the below code is enough:
There are several options:
|
It looks like
I would just use that as it's backward-compatible. EDIT: Ah - the browser! Right. The standard way of using globals and then shimming is to check |
Pull Request Test Coverage Report for Build 659580814
💛 - Coveralls |
Fixes #3385
Details
Replace
Buffer
operations withTextDecoder
/TextEncoder
and other libraries.(btoa-lite
)Support binary input for prebuilt function
string
Now,
string
would support converting a binary object into a normal string withUTF-8
decoding.For example:
string(binary('hello'))
-> 'hello'Refine
fromFile
Originally,
fromFile
accepts only one parameter that refers to the file path. The step is as follows:In this PR, we introduce the second parameter of
fromFile
.Its value could be:
evaluated (default)
,raw
orbinary
So the change of this function is:
fromFile(path: string)
->fromFile(path: string, format: 'evaluated'(default) | 'raw' | 'binary')
raw
formatIn some situations, users do not want to evaluate the text, and just want to keep the original content text.
Example:
There is a file, xx.txt, content is:
Original, user could use
fromFile('xx.txt')
to gethi jack
,hi Lucy
,etc. according to the memory/properties passed in.But there is no way to get the original text.
Now, user could use
fromFile('xx.txt', 'raw')
to gethi ${name}
binary
formatIn another situation, the user wants to get the binary result of the file.
Example:
string(fromFile('xx.txt', 'binary'))
=> 'hi ${name}'If you want to evaluate it directly, just append
expandText
function:expandText(string(fromFileBinary('xx.txt')))
=> 'hi Jack', 'hi Lucy' ...Another example for Bot builder:
For Bot response, if the user wants to send a local image to the client, here is the solution: