<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <dynamic.h>

#include "stream.h"

static int stream_need(stream *stream, size_t size)
{
  if (stream_valid(stream) && size <= stream_size(stream))
    return 1;

  stream_destruct(stream);
  return 0;
}

static int stream_writable(stream *stream)
{
  if (stream_valid(stream) && stream->buffer)
    return 1;

  stream_destruct(stream);
  return 0;
}

void stream_construct(stream *stream, void *data, size_t size)
{
  *stream = (struct stream) {0};
  stream->data = data;
  stream->end = size;
}

void stream_construct_buffer(stream *stream, buffer *buffer)
{
  *stream = (struct stream) {0};
  stream->buffer = buffer;
  stream->data = buffer_data(stream->buffer);
  stream->begin = 0;
  stream->end = 0;
}

void stream_destruct(stream *stream)
{
  *stream = (struct stream) {0};
}

int stream_valid(stream *stream)
{
  return stream->buffer != NULL || stream->data != NULL;
}

void *stream_data(stream *stream)
{
  return stream->data;
}
<commit_msg>Construct stream from buffer with correct size<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <dynamic.h>

#include "stream.h"

static int stream_need(stream *stream, size_t size)
{
  if (stream_valid(stream) && size <= stream_size(stream))
    return 1;

  stream_destruct(stream);
  return 0;
}

static int stream_writable(stream *stream)
{
  if (stream_valid(stream) && stream->buffer)
    return 1;

  stream_destruct(stream);
  return 0;
}

void stream_construct(stream *stream, void *data, size_t size)
{
  *stream = (struct stream) {0};
  stream->data = data;
  stream->end = size;
}

void stream_construct_buffer(stream *stream, buffer *buffer)
{
  *stream = (struct stream) {0};
  stream->buffer = buffer;
  stream->data = buffer_data(stream->buffer);
  stream->begin = 0;
  stream->end = buffer_size(stream->buffer);
}

void stream_destruct(stream *stream)
{
  *stream = (struct stream) {0};
}

int stream_valid(stream *stream)
{
  return stream->buffer != NULL || stream->data != NULL;
}

void *stream_data(stream *stream)
{
  return stream->data;
}

{'fraction_non_alphanumeric': 0.1492399815753109, 'fraction_numerical': 0.00783049286043298, 'mean_word_length': 4.626943005181347, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4186472', 'n_tokens_mistral': 776, 'n_tokens_neox': 750, 'n_words': 188}