Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/choefele/cchbinarydata
Utility classes for handling binary data
https://github.com/choefele/cchbinarydata
Last synced: 3 months ago
JSON representation
Utility classes for handling binary data
- Host: GitHub
- URL: https://github.com/choefele/cchbinarydata
- Owner: choefele
- License: mit
- Created: 2014-08-12T21:19:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-16T17:49:24.000Z (over 9 years ago)
- Last Synced: 2024-03-15T07:02:16.441Z (10 months ago)
- Language: Objective-C
- Size: 230 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CCHBinaryData
=============Utility classes for handling binary data, such as reading various data types from byte buffers.
[![Build Status](https://img.shields.io/travis/choefele/CCHBinaryData.svg)](https://travis-ci.org/choefele/CCHBinaryData) ![Version](https://img.shields.io/cocoapods/v/CCHBinaryData.svg) ![Platform](http://img.shields.io/cocoapods/p/CCHBinaryData.svg)
See [Releases](https://github.com/choefele/CCHBinaryData/releases) for a high-level overview of recent updates.
Need to talk to a human? [I'm @claushoefele on Twitter](https://twitter.com/claushoefele).
## Installation
Use [CocoaPods](http://cocoapods.org) to integrate `CCHBinaryData` into your project. Minimum deployment targets are 7.0 for iOS and 10.9 for OS X.
```ruby
platform :ios, '7.0'
pod "CCHBinaryData"
``````ruby
platform :osx, '10.9'
pod "CCHBinaryData"
```## Reading binary data
`CCHBinaryDataReader` can read various data types from byte buffers provided as `NSData`. The following sample code reads chunk information from a PNG image file:
```Objective-C
// Read PNG file. Data is big endian, see http://www.w3.org/TR/PNG/#7Integers-and-byte-order
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"pngbar" ofType:@"png"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
CCHBinaryDataReader *binaryDataReader = [[CCHBinaryDataReader alloc] initWithData:data options:CCHBinaryDataReaderBigEndian];
// Skip file signature
[binaryDataReader setNumberOfBytesRead:8];
// Read chunks, see http://www.w3.org/TR/PNG/#5Chunk-layout
while ([binaryDataReader canReadNumberOfBytes:4]) {
unsigned int length = [binaryDataReader readUnsignedInt];
NSString *chunkType = [binaryDataReader readStringWithNumberOfBytes:4 encoding:NSASCIIStringEncoding];
[binaryDataReader skipNumberOfBytes:length];
unsigned int crc = [binaryDataReader readUnsignedInt];
[NSLog(@"%@ length: %tu, crc: 0x%08x\n", chunkType, length, crc];
}
```