Lotus IBM
--
Questions
--
Followers
Top Experts
There are several ways to do this. Â One of them involves using NotesStream. Â NotesStream.WriteText loads the steam from a String. Â NotesStream.Read returns an array of Bytes. Â So far so good (and very fast)!
The only problem I have it that NotesStream.Read returns an array that is twice as long as the input string, and every other element in the array is set to zero (0). Â I think this is caused by the width of a character in a LotusScript string being 2-bytes, but I want to understand this better. Â I can workaround the problem by removing the odd elements, but I would rather not have to do this since this limits the size of the string that can be converted.
Below is a test agent that illustrates this problem. Â The test.txt file contains "12345" with no quotes. Â Both streams use the "Unicode" character set.
The image below is from the debugger at the Stop line. Â Notice that stream1's size is 10 bytes and stream2's size is 5 bytes. Â Also notice the values stored in the resulting bytes arrays.
As I mentioned above, I have a workaround that removes the extra elements, but since the return array is double the size I need, this limits the size of the input string to 16,383 rather than 32,767 (without splitting the string into chunks).
Does anyone know how to make NotesStream work the way I want?
Sub Initialize
Dim sess As New NotesSession
Dim stream1 As NotesStream
Dim stream2 As NotesStream
Dim bytes1 As Variant
Dim bytes2 As Variant
Set stream1 = sess.CreateStream
Call stream1.WriteText("12345")
stream1.Position = 0
bytes1 = stream1.Read
Set stream2 = sess.CreateStream
Call stream2.Open("c:\temp\test.txt", "Unicode")
stream1.Position = 0
bytes2 = stream2.Read
Stop
End Sub
streams.GIF
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I also have been intending to use blowfish in a project. Here's an extract of the code:
Declare Sub bfinit Lib "blowfish.dll" Alias "bfinit" (Byval s As String, Byval l As Integer)
Declare Sub bfxcrypt Lib "blowfish.dll" Alias "bfxcrypt" (Byval s As String, Byval t As String, Byval l As Integer)
Declare Sub bfxdecrypt Lib "blowfish.dll" Alias "bfxdecrypt" (Byval s As String, Byval t As String, Byval l As Integer)
Again, if I can find those sources... Sheesh, what chaos... The general idea being: why on earth do you write it in LotusScript?? Ah, portability... You have a point there, although a .dll can be converted into a .so-file without a lot of trouble. Let me check my archives... I'll be back!
      Dim filename As String
      On Error Resume Next
      filename = "C:\icon1.ico"  Â
      Kill filename
      On Error Goto 0
      If Not stream.Open( filename, "Binary") Then
           Messagebox "Export Icon: Cannot write picture " & filename
           Exit Sub
      End If       Â
      Dim buffer As Variant
      stream3.Position= 0
      Do
           buffer = stream3.Read(32767)
           Call stream.Write(buffer)
      Loop Until stream.IsEOS
     Â
      Call stream.Close()
Regarding the use of ASCII -- you can only specify the encoding when you're opening files (the WriteText method does not have a "charset" parameter). Â The encoding defaults to "Unicode" for new objects, and the Charset property is read-only, so there's no way to change it unless you open a file (which would defeat my purpose). Â That's why I explicitly used "Unicode" to read from the file -- so I could compare apples to apples. Â Unfortunately for me, "String Apples" apparently taste differently from "File Apples". Â Â :)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Eh, did you try with the method Write instead of WriteText ?? I suppose that Read should be used to get the data out when Write was used to put the data in. And ReadText vs WriteText.
I tried using Write instead of WriteText, but Write  throws an error if you don't pass in a byte array.
I've given up on trying to get an unpadded array out of NotesStream, but there are other options. Â Here's where I am on this:
- If WIN32 is defined, I use RtlMoveMemory to convert the string to a byte array.
- Otherwise, if the string length is >Â 16383, split the string into 16383 byte long chunks, process each chunk independently, return the results joined into a single Byte array.
- Otherwise, use NotesStream (WriteText->Read) to convert the sting to a byte array.
This should work well and support any string length.
My problem now is that I can't get Arrayappend to work on a byte array!
Man, it's always something!
To illustrate this LotusScript "bug", I created 2 agents (posted below). Â The first one works, but the second one throws a Type Mismatch error on Arrayappend.
I already have a function that I use that wraps up Arrayappend to support null arrays, scalar arguments and objects. Â I'd hate to have to add special-case handling for byte arrays as well.
Any thoughts on this issue?
Sub Initialize
' This one works.
Dim arr1(0) As Long
Dim arr2(0) As Long
Dim arr3 As Variant
arr1(0) = 1
arr2(0) = 2
arr3 = Arrayappend(arr1, arr2)
End Sub
Sub Initialize
' This one fails.
Dim arr1(0) As Byte
Dim arr2(0) As Byte
Dim arr3 As Variant
arr1(0) = 1
arr2(0) = 2
arr3 = Arrayappend(arr1, arr2) ' Type mismatch!
End Sub

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Sub Initialize
' This one fails.
Dim arr1(0) As Byte
Dim arr2(0) As Byte
Dim arr3 As Variant
arr1(0) = 1
arr2(0) = 2
arr3 = Mid(arr1, arr2)
End Sub
Sub Initialize
  Â
   ' This one fails.
   Dim arr1 As String*100
   Dim arr2 As String*100
   Dim arr3 As Variant
   arr1 = "1234"
   arr2= "5678"
   Mid(arr1, 4)= arr2 Â
  Â
End Sub
Check the example in the help. I think that this won't help you if you moved to Bytes all the way... Sorry if I lead you into the wrong direction.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I'll put that on my list of things to try.
Lotus IBM
--
Questions
--
Followers
Top Experts
Lotus Software produced the Lotus 1-2-3 spreadsheet program, and later developed Lotus Notes, a groupware and email system. Following its acquisition by IBM, the Notes and Domino client/server collaborative platform were expanded to include functions such as email, calendars, to-do lists, contacts management, teamrooms, discussion forums, file sharing, microblogging, instant messaging, blogs, and user directories. IBM also release SmartSuite, a comprehensive office suite, and followed that with Symphony, unrelated to the Lotus suite of the same name.