Swiftpack.co - Xenoxiluna/SwiftyBytes as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Xenoxiluna.
Xenoxiluna/SwiftyBytes 0.4.5
A binary read/write library written in Swift.
⭐️ 6
🕓 3 years ago
.package(url: "https://github.com/Xenoxiluna/SwiftyBytes.git", from: "0.4.5")

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

GitHub

link
Stars: 6
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v0.4.5
3 years ago

Corrected Protection for BinaryWriter WriteIndex Property

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics