Notifications
Clear all

[Closed] Cut binary data to a new one issue

Hi,I am using a copy command to cut a binary stream to a new one,I don’t know why it does not work,any help?

test_file=@"C:\abc.txt"
sourceArray=(dotnetclass "System.IO.File").ReadAllBytes test_file asdotnetobject:on
needArray=dotNetClass "System.Byte[]"

--Copy <System.Array>sourceArray <System.Int64>sourceIndex <System.Array>destinationArray <System.Int64>destinationIndex <System.Int64>length

sourceArray.Copy sourceArray 3 needArray 1 3

-- Runtime error: No method found which matched argument list
2 Replies

needArray must be an array instance, not a class.

test_file=@"D:\abc.txt"
sourceIndex = 3			--	starting index is 0, so 3 is the fourth element
bytesToCopy = 3
destinationIndex = 1	--	starting index is 0, so 1 is the second element

sourceArray=(dotnetclass "System.IO.File").ReadAllBytes test_file asdotnetobject:on
needArray=dotNetObject "System.Byte[]" (bytesToCopy + destinationIndex)

--Copy <System.Array>sourceArray <System.Int64>sourceIndex <System.Array>destinationArray <System.Int64>destinationIndex <System.Int64>length

sourceArray.Copy sourceArray sourceIndex needArray destinationIndex bytesToCopy

/* Check
for i = 1 to bytesToCopy do
(
	format "Source[%] = %; Destination[%] = %\n" (sourceIndex+i-1) (sourceArray.GetValue (sourceIndex+i-1)) (destinationIndex+i-1) (needArray.GetValue (destinationIndex+i-1))
)
*/

It’s works,thanks for pointing out the reason and thanks for help