VFK / Bitfield

A Swift bitfield implementation compatible with BitTorrent specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

bitfield.data {get set} // Swift Data type 

About

A Swift bitfield implementation compatible with BitTorrent specification

License:MIT License


Languages

Language:Swift 100.0%