<commit_before>package lzb

type readBuffer struct {
	*buffer
	dict *dict
	head int64
}

func (r *readBuffer) Seek(offset int64, whence int) (off int64, err error) {
	switch whence {
	case 0:
		off = offset
	case 1:
		off = r.head + offset
	case 2:
		off = r.top + offset
	default:
		return r.head, errWhence
	}
	if !(r.bottom <= off && off <= r.top) {
		return r.head, errOffset
	}
	r.head = off
	r.writeLimit = off + int64(r.capacity())
	return
}

func newReadBuffer(capacity int64, dictsize int64) (r *readBuffer, err error) {
	b, err := newBuffer(capacity)
	if err != nil {
		return nil, err
	}
	d, err := newDict(b, 0, dictsize)
	if err != nil {
		return nil, err
	}
	r = &readBuffer{buffer: b, dict: d, head: 0}
	return r, nil
}

func (r *readBuffer) Read(p []byte) (n int, err error) {
	n, err = r.ReadAt(p, r.head)
	if err != nil {
		return 0, err
	}
	_, err = r.Seek(int64(n), 1)
	if err != nil {
		return 0, err
	}
	return
}

func (r *readBuffer) Write(p []byte) (n int, err error) {
	n, err = r.buffer.Write(p)
	_, serr := r.dict.Seek(int64(n), 1)
	if err == nil {
		err = serr
	}
	return
}

func (r *readBuffer) WriteByte(c byte) error {
	err := r.buffer.WriteByte(c)
	if err != nil {
		return err
	}
	_, err = r.dict.Seek(1, 1)
	return err
}
<commit_msg>lzb: seek of read head necessary in read buffer to set writeLimit<commit_after>package lzb

type readBuffer struct {
	*buffer
	dict *dict
	head int64
}

func (r *readBuffer) Seek(offset int64, whence int) (off int64, err error) {
	switch whence {
	case 0:
		off = offset
	case 1:
		off = r.head + offset
	case 2:
		off = r.top + offset
	default:
		return r.head, errWhence
	}
	if !(r.bottom <= off && off <= r.top) {
		return r.head, errOffset
	}
	r.head = off
	r.writeLimit = off + int64(r.capacity())
	return
}

func newReadBuffer(capacity int64, dictsize int64) (r *readBuffer, err error) {
	b, err := newBuffer(capacity)
	if err != nil {
		return nil, err
	}
	d, err := newDict(b, 0, dictsize)
	if err != nil {
		return nil, err
	}
	r = &readBuffer{buffer: b, dict: d}
	if _, err = r.Seek(0, 0); err != nil {
		return nil, err
	}
	return r, nil
}

func (r *readBuffer) Read(p []byte) (n int, err error) {
	n, err = r.ReadAt(p, r.head)
	if err != nil {
		return 0, err
	}
	_, err = r.Seek(int64(n), 1)
	if err != nil {
		return 0, err
	}
	return
}

func (r *readBuffer) Write(p []byte) (n int, err error) {
	n, err = r.buffer.Write(p)
	_, serr := r.dict.Seek(int64(n), 1)
	if err == nil {
		err = serr
	}
	return
}

func (r *readBuffer) WriteByte(c byte) error {
	err := r.buffer.WriteByte(c)
	if err != nil {
		return err
	}
	_, err = r.dict.Seek(1, 1)
	return err
}

{'fraction_non_alphanumeric': 0.15049279757391965, 'fraction_numerical': 0.02084912812736922, 'mean_word_length': 3.104199066874028, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3901587', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1102, 'n_words': 342}