<commit_before>#ifndef DIGGLER_IO_STREAM_HPP
#define DIGGLER_IO_STREAM_HPP

#include <goodform/io.hpp>

#include "../Platform.hpp"

namespace Diggler {

class Stream {
public:
  using SizeT = uint64;
  using PosT = SizeT;
  using OffT = int64;
};

class SeekableStream : public virtual Stream {
public:
  enum Whence {
    Set,
    Current,
    // End
  };

  virtual PosT tell() const = 0;
  virtual void seek(OffT, Whence = Set) = 0;
  inline void seek(PosT pos) {
    seek(static_cast<OffT>(pos), Whence::Set);
  }
};

class SizedStream : public virtual SeekableStream {
public:
  virtual SizeT length() const = 0;
  virtual SizeT remaining() const {
    return length() - tell();
  }
};

class InStream : public virtual Stream, public goodform::istream {
public:
  virtual std::string readString();
  virtual std::u32string readString32();
  virtual bool readBool();
  virtual int64 readI64();
  virtual uint64 readU64();
  virtual int32 readI32();
  virtual uint32 readU32();
  virtual int16 readI16();
  virtual uint16 readU16();<commit_msg>io/Stream: add rewind() (seeks to 0)<commit_after>#ifndef DIGGLER_IO_STREAM_HPP
#define DIGGLER_IO_STREAM_HPP

#include <goodform/io.hpp>

#include "../Platform.hpp"

namespace Diggler {

class Stream {
public:
  using SizeT = uint64;
  using PosT = SizeT;
  using OffT = int64;
};

class SeekableStream : public virtual Stream {
public:
  enum Whence {
    Set,
    Current,
    // End
  };

  virtual PosT tell() const = 0;
  virtual void seek(OffT, Whence = Set) = 0;
  inline void seek(PosT pos) {
    seek(static_cast<OffT>(pos), Whence::Set);
  }

  inline void rewind() {
    seek(static_cast<OffT>(0));
  }
};

class SizedStream : public virtual SeekableStream {
public:
  virtual SizeT length() const = 0;
  virtual SizeT remaining() const {
    return length() - tell();
  }
};

class InStream : public virtual Stream, public goodform::istream {
public:
  virtual std::string readString();
  virtual std::u32string readString32();
  virtual bool readBool();
  virtual int64 readI64();
  virtual uint64 readU64();
  virtual int32 readI32();
  virtual uint32 readU32();
  virtual int16 readI16();
  virtual uint16 readU16();
{'fraction_non_alphanumeric': 0.1179440110142267, 'fraction_numerical': 0.03304268012849931, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4778363', 'n_tokens_mistral': 780, 'n_tokens_neox': 732, 'n_words': 214}