@@ -34,7 +34,7 @@ naughtyStrings = [
3434 "file^name^with^carats^.txt" ,
3535 "file&name&with&s&.txt" ,
3636 "file*name*with*asterisks*.txt" ,
37- "file_name_with_long_name_exceeding_255_characters_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz .txt" ,
37+ "file_name_with_long_name_exceeding_255_characters_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz .txt" ,
3838 "file👍name👍with👍thumbs👍up.txt" ,
3939 "invisible\u200Bname.txt" , // Invisible Unicode character (Zero Width Space)
4040 "invisible\u200Cname.txt" , // Invisible Unicode character (Zero Width Non-Joiner)
@@ -693,4 +693,45 @@ window.fsTests = [
693693 }
694694 }
695695 } ,
696+ {
697+ name : "testFSWriteReadBinaryFile" ,
698+ description : "Test writing and reading binary file data and verify it remains intact" ,
699+ test : async function ( ) {
700+ try {
701+ let randName = puter . randName ( ) + '.webp' ;
702+
703+ // Create some binary data - a simple byte array representing a small binary file
704+ const binaryData = new Uint8Array ( [
705+ 0x52 , 0x49 , 0x46 , 0x46 , 0x24 , 0x00 , 0x00 , 0x00 , 0x57 , 0x45 , 0x42 , 0x50 , 0x56 , 0x50 , 0x38 , 0x20 ,
706+ 0x18 , 0x00 , 0x00 , 0x00 , 0x30 , 0x01 , 0x00 , 0x9D , 0x01 , 0x2A , 0x01 , 0x00 , 0x01 , 0x00 , 0x02 , 0x00 ,
707+ 0x34 , 0x25 , 0xA4 , 0x00 , 0x03 , 0x70 , 0x00 , 0xFE , 0xFB , 0xFD , 0x50 , 0x00
708+ ] ) ;
709+
710+ // Write the binary data to a file
711+ const writeResult = await puter . fs . write ( randName , binaryData ) ;
712+ assert ( writeResult . uid , "Failed to write binary file" ) ;
713+
714+ // Read the binary data back
715+ const readResult = await puter . fs . read ( randName ) ;
716+ const readBinaryData = new Uint8Array ( await readResult . arrayBuffer ( ) ) ;
717+
718+ // Verify the binary data is identical
719+ assert ( readBinaryData . length === binaryData . length , "Binary data length mismatch" ) ;
720+ for ( let i = 0 ; i < binaryData . length ; i ++ ) {
721+ assert ( readBinaryData [ i ] === binaryData [ i ] , `Binary data mismatch at byte ${ i } : expected ${ binaryData [ i ] } , got ${ readBinaryData [ i ] } ` ) ;
722+ }
723+
724+ pass ( "testFSWriteReadBinaryFile passed" ) ;
725+
726+ // Clean up - delete the test file
727+ try {
728+ await puter . fs . delete ( randName ) ;
729+ } catch ( error ) {
730+ fail ( "testFSWriteReadBinaryFile failed to delete file:" , error ) ;
731+ }
732+ } catch ( error ) {
733+ fail ( "testFSWriteReadBinaryFile failed:" , error ) ;
734+ }
735+ }
736+ } ,
696737] ;
0 commit comments