User bio
404 bio not found
Member since Jun 6, 2021
Posts:
Replies:
There is a limit to string length, as explained in the documentation.
To convert a binary stream to a base64 encoded character stream, you have to call the function in a loop using a buffer. Due the way the function works, the buffer length must be a multiple of 57.
Here a sample implementation, from ks.lib.stream.Utils class in the ks-iris-lib package available on Open Exchange.
/// encode stream data into encoded using bufferSize (due the implementation of $system.Encryption.Base64Encode, this must be a multiple of 57)
ClassMethod Base64Encode(stream As %Stream.Object, Output encoded As %Stream.Object, bufferSize As %Integer = 5700) As %Status
{
#Dim sc as %Status
#Dim ex as %Exception.AbstractException
#Dim len As %Integer
s sc = $$$OK
try {
throw:((bufferSize#57)'=0) ##class(%Exception.General).%New("buffer size must be a multiple of 57")
$$$TOE(sc,stream.Rewind())
s:'$d(encoded) encoded = ##class(%Stream.TmpCharacter).%New()
s len=bufferSize
while 'stream.AtEnd {
$$$TOE(sc,encoded.Write($system.Encryption.Base64Encode(stream.Read(.len),1)))
s len = bufferSize
}
}
catch (ex) {
s sc = ex.AsStatus()
}
return sc
}
Using the second approach : edited down to 39 characters
ClassMethod ascii()
{
f i=32:1:126 w:$t(ascii+1)'[$c(i) *i
}
Open Exchange applications:
Certifications & Credly badges:
Robert has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Following:
Robert has not followed anybody yet.
For example (in open exchange package ks-iris-lib) :
/// list of data types exposing %GetSerial and %SetSerial Class ks.lib.collections.ListOfDataTypes Extends %Library.ListOfDataTypes { /// serialize object Method %GetSerial(force As %Integer = 0) As %String { return ##super(force) } /// deserialize object Method %SetSerial(serialized As %String) As %Status { return ##super(.serialized) } Storage Custom { <Type>%Library.CompleteCustomStorage</Type> } }