Skip to content

Xenoxiluna/SwiftyBytes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyBytes

Swift 5.X GitHub license Docs Build Status

A binary file read/write library written in swift. It was created with the purpose of being able to somewhat easily read game data files.

NOTE: writeString prefixes the length of the given string as a generic Int. This could cause compatibility issues on 32/64-bit systems

Usage

Write: LittleEndian

var writeTest: BinaryWriter = BinaryWriter()
try writeTest.writeVariableLengthString("This is a test!", .ascii)
try writeTest.writeNullTerminatedString("This is my second test!", .ascii)
try writeTest.writeUInt64(866464616516564)

Write: BigEndian

var writeTest: BinaryWriter = BinaryWriter()
try writeTest.writeUInt64(866464616516564, bigEndian: true)

Read: LittleEndian

var reader: BinaryReader = BinaryReader(writeTest.data)
print("\(try reader.readVariableLengthString(.ascii))")
print("\(try reader.readNullTerminatedString(.ascii))")
print("\(try reader.readUInt64())")

Read: BigEndian

var reader: BinaryReader = BinaryReader(writeTest.data)
print("\(try reader.readUInt64(true))")

License

SwiftyBytes is licensed under the MIT License