none
Binary read/write with files RRS feed

  • General discussion

  • Hello!

     

    I have suggestion for the next version: reading/writing binary data from/to file.

    Now I can do this with strings but Unicode conversions change my data

     

    mydata=""
    For i=0 To 255
     mydata = mydata +Text.GetCharacter(i)
    EndFor
    ' mydata length is now 256
    
    File.WriteContents("gt.txt", mydata)
    'file size is now 384
    
     
    

     

     

    I have two "smallbasic style" ideas

    1. File.ReadByte(filePath, offset) / File.WriteByte(filePath, offset, contents) / File.Size(filePath)

    2. File.BinaryReadArray(filePath) / File.BinaryWriteArray(filePath,contents)

     

    Does it makes sense for Vijaye and for you?


    Grzesio
    Saturday, June 5, 2010 7:39 PM

All replies

  • Yes, it does make sense to have this capability, but sticking with existing SB convention, I'd suggest...

     

    contents = Text.GetCharacter(97) + Text.GetCharacter(12) + Text.GetCharacter(254) etc.

    File.BinaryWriteContents( filePath, contents )

    contents = File.BinaryReadContents( filePath )

     

    and of course, File.BinaryAppendContents( filePath, contents )

     

    [ with the possible extra complexity of... File.BinaryReadContents( filePath, start, length ) ]

    Monday, June 7, 2010 10:36 PM
  • It makes sense too.

    Any method will be OK for me if it will write exactly what I put into my variable.

     


    Grzesio
    Tuesday, June 8, 2010 8:00 AM
  • I think i can do binary extension for small basic but i can't understand where in my small basic program I can use it? Do we really need binary extension? How about .zip extension?

    Sorry My Bad English
    Wednesday, June 9, 2010 2:03 PM