https://github.com/vfk/bitfield
A Swift bitfield implementation compatible with BitTorrent specification
https://github.com/vfk/bitfield
bitfield bittorrent spm swift
Last synced: 9 months ago
JSON representation
A Swift bitfield implementation compatible with BitTorrent specification
- Host: GitHub
- URL: https://github.com/vfk/bitfield
- Owner: VFK
- License: mit
- Created: 2020-01-03T11:02:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-03T11:57:01.000Z (about 6 years ago)
- Last Synced: 2024-12-24T15:17:53.674Z (about 1 year ago)
- Topics: bitfield, bittorrent, spm, swift
- Language: Swift
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bitfield
A simple bitfield implementation written in Swift for use with Package Manager.
Compatible with BitTorrent specifucation:
> <...> a bitfield representing the pieces that have been successfully downloaded. The high bit in the first byte corresponds to piece index 0. Bits that are cleared indicated a missing piece, and set bits indicate a valid and available piece. Spare bits at the end are set to zero.
## Usage
```swift
import Bitfield
let bitfield = Bitfield(size: 10)
bitfield.set(atIndex: Int) // Sets bit at specified index to 1
bitfield.unset(atIndex: Int) // Sets bit at specified index to 0
bitfield.isSet(atIndex: Int) -> Bool
```
To access (or set directly) bitfield data use
```swift
bitfield.data {get set} // Swift Data type
```