void abytewriter::write_n( unsigned char* byte, int n )
{
	// safety check for error
	if ( error ) return;

	// make sure that pointer doesn't get beyond flush threshold
	while ( ( cbyte + n ) >= ( dsize - 2 ) ) {
        unsigned char * newData = aligned_alloc(dsize *  2);
        memcpy(newData, data, dsize);
        dsize *= 2;
        aligned_dealloc(data);
        data = newData;
		if ( data == NULL ) {
            error = true;
            custom_exit(ExitCode::MALLOCED_NULL);
			return;
		}
	}

	// copy data from array
	while ( n-- > 0 )
		data[ cbyte++ ] = *(byte++);
}
void abytewriter::write_n( unsigned char* byte, int n )
{
	 
	if ( error ) return;

	 
	while ( ( cbyte + n ) >= ( dsize - 2 ) ) {
        unsigned char * newData = aligned_alloc(dsize *  2);
        memcpy(newData, data, dsize);
        dsize *= 2;
        aligned_dealloc(data);
        data = newData;
		if ( data == NULL ) {
            error = true;
            custom_exit(ExitCode::MALLOCED_NULL);
			return;
		}
	}

	 
	while ( n-- > 0 )
		data[ cbyte++ ] = *(byte++);
}