<commit_before>package bsdiff

import (
	"errors"
	"fmt"
	"io"
	"io/ioutil"

	humanize "github.com/dustin/go-humanize"
)

// ErrCorrupt indicates that a patch is corrupted, most often that it would produce a longer file
// than specified
var ErrCorrupt = errors.New("corrupt patch")

// ReadMessageFunc should read the passed protobuf and relay any errors.
// See the `wire` package for an example implementation.
type ReadMessageFunc func(msg interface{}) error

// BSPatch applies patch to old, according to the bspatch algorithm,
// and writes the result to new.
func BSPatch(old io.Reader, new io.Writer, newSize int64, readMessage ReadMessageFunc) error {
	// TODO: still debating whether we should take an io.ReadSeeker instead... probably?
	// the consumer can still do `ReadAll` themselves and pass a bytes.NewBuffer()
	obuf, err := ioutil.ReadAll(old)
	if err != nil {
		return err
	}

	// TODO: write directly to new instead of using a buffer
	nbuf := make([]byte, newSize)

	var oldpos, newpos int64

	ctrl := &Control{}
<commit_msg>BSPatch => Patch<commit_after>package bsdiff

import (
	"errors"
	"fmt"
	"io"
	"io/ioutil"

	humanize "github.com/dustin/go-humanize"
)

// ErrCorrupt indicates that a patch is corrupted, most often that it would produce a longer file
// than specified
var ErrCorrupt = errors.New("corrupt patch")

// ReadMessageFunc should read the passed protobuf and relay any errors.
// See the `wire` package for an example implementation.
type ReadMessageFunc func(msg interface{}) error

// Patch applies patch to old, according to the bspatch algorithm,
// and writes the result to new.
func Patch(old io.Reader, new io.Writer, newSize int64, readMessage ReadMessageFunc) error {
	// TODO: still debating whether we should take an io.ReadSeeker instead... probably?
	// the consumer can still do `ReadAll` themselves and pass a bytes.NewBuffer()
	obuf, err := ioutil.ReadAll(old)
	if err != nil {
		return err
	}

	// TODO: write directly to new instead of using a buffer
	nbuf := make([]byte, newSize)

	var oldpos, newpos int64

	ctrl := &Control{}

{'fraction_non_alphanumeric': 0.09583133684714902, 'fraction_numerical': 0.003833253473885961, 'mean_word_length': 4.0071942446043165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '7341809', 'n_tokens_mistral': 652, 'n_tokens_neox': 626, 'n_words': 259}