35#define DATA_BLOCK_SIZE 4096
75 const Range range = { 0, this->length };
95 if (this->length == that->
length) {
96 return memcmp(this->bytes, that->
bytes, this->length) == 0;
147 ident mem = malloc(length);
150 memcpy(mem, bytes, length);
178 FILE *file = fopen(path,
"rb");
182 int err = fseek(file, 0, SEEK_END);
185 const size_t length = ftell(file);
188 mem = malloc(length);
191 err = fseek(file, 0, SEEK_SET);
194 const size_t read = fread(mem, length, 1, file);
236 FILE *file = fopen(path,
"w");
242 count = fwrite(self->
bytes, self->
length, 1, file);
255#pragma mark - Class lifecycle
291 .instanceSize =
sizeof(
Data),
292 .interfaceOffset = offsetof(
Data, interface),
293 .interfaceSize =
sizeof(DataInterface),
static void destroy(Class *clazz)
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static void initialize(Class *clazz)
int HashForInteger(int hash, const long integer)
Accumulates the hash value of integer into hash.
int HashForBytes(int hash, const uint8_t *bytes, const Range range)
Accumulates the hash value of bytes into hash.
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
void * ident
The identity type, similar to Objective-C id.
#define do_once(once, block)
Executes the given block at most one time.
MutableArray * mutableCopy(const Array *self)
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
Class * _Data(void)
The Data archetype.
Data * initWithContentsOfFile(Data *self, const char *path)
Initializes this Data with the contents of the file at path.
Data * dataWithBytes(const uint8_t *bytes, size_t length)
Returns a new Data by copying length of bytes.
Data * initWithMemory(Data *self, ident mem, size_t length)
Initializes this Data, taking ownership of the specified memory.
DataDestructor destroy
An optional destructor that, if set, is called on dealloc.
Data * dataWithMemory(ident mem, size_t length)
Returns a new Data, taking ownership of the specified memory.
Data * dataWithContentsOfFile(const char *path)
Returns a new Data with the contents of the file at path.
size_t length
The length of bytes.
uint8_t * bytes
The bytes.
MutableData * mutableCopy(const Data *self)
Data * initWithConstMemory(Data *self, const ident mem, size_t length)
Initializes this Data with the given const memory.
_Bool writeToFile(const Data *self, const char *path)
Writes this Data to path.
Data * initWithBytes(Data *self, const uint8_t *bytes, size_t length)
Initializes this Data by copying length of bytes.
Data * dataWithConstMemory(const ident mem, size_t length)
Returns a new Data, backed by the given const memory.
MutableData * initWithData(MutableData *self, const Data *data)
Initializes this Data with the contents of data.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
A location and length into contiguous collections.
int read(StringReader *self)
Reads a single Unicode code point from this StringReader.