Skip to content
/ Bitfield Public

A Swift bitfield implementation compatible with BitTorrent specification

License

Notifications You must be signed in to change notification settings

VFK/Bitfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages