<commit_before>package torrent

import (
	"github.com/nsf/libtorgo/bencode"
	"path/filepath"
	"errors"
	"hash"
	"crypto/sha1"
	"time"
	"sort"
	"io"
	"os"
)

// The Builder type is responsible for .torrent files construction. Just
// instantiate it, call necessary methods and then call the .Build method. While
// waiting for completion you can use 'status' channel to get status reports.
type Builder struct {
	filesmap      map[string]bool
	files         []file
	files_size    int64
	name          string
	piece_length  int64
	pieces        []byte
	private       bool
	announce_list [][]string
	creation_date time.Time
	comment       string
	created_by    string
	encoding      string
	urls          []string
}

// Adds a file to the builder queue. You may add one or more files.
func (b *Builder) AddFile(filename string) {
	if b.filesmap == nil {
		b.filesmap = make(map[string]bool)
	}

	filename, err := filepath.Abs(filename)
	if err != nil {
		panic(err)
	}
	b.filesmap[filename] = true
}

// Defines a name of the future torrent file. For single file torrents it's the
// recommended name of the contained file. For multiple files torrents it's the
// recommended name of the directory in which all of them will be
// stored. Calling this function is not required. In case if no name was
// specified, the builder will try to automatically assign it. It will use the
// name of the file if there is only one file in the queue or it will try to
// find the rightmost common directory of all the queued files and use its name as
// a torrent name. In case if name cannot be assigned automatically, it will use
// "unknown" as a torrent name.
func (b *Builder) SetName(name string) {
	b.name = name
}

// Sets the length of a piece in the torrent file in bytes. The default is
// 256kb.
func (b *Builder) SetPieceLength(length int64) {
	b.piece_length = length
}

// Sets the "private" flag. The default is false.
func (b *Builder) SetPrivate(v bool) {
	b.private = v
}

// Add announce group. TODO: better explanation.
func (b *Builder) AddAnnounceGroup(group []string) {
	b.announce_list = append(b.announce_list, group)
}

// Sets creation date. The default is time.Now() when the .Build method was
// called.
func (b *Builder) SetCreationDate(date time.Time) {
	b.creation_date = date
}

// Sets the comment. The default is no comment.
func (b *Builder) SetComment(comment string) {
	b.comment = comment
}

// Sets the "created by" parameter. The default is "libtorgo".
func (b *Builder) SetCreatedBy(createdby string) {
	b.created_by = createdby
}

// Sets the "encoding" parameter. The default is "UTF-8".
func (b *Builder) SetEncoding(encoding string) {
	b.encoding = encoding
}

func (b *Builder) AddURL(url string) {
	b.urls = append(b.urls, url)
}

// Status report structure for Builder.Build method.
type BuilderStatus struct {
	Size int64
	Hashed int64
}

// Builds a torrent file. This function does everything in a separate goroutine
// and uses up to 'nworkers' of goroutines to perform SHA1 hashing. Therefore it
// will return almost immedately. It returns two channels, the first one is for
// completion awaiting, the second one is for getting status reports. You should
// not call any other methods while the builder is working on the torrent file.
func (b *Builder) Build(w io.Writer, nworkers int) (<-chan error, <-chan BuilderStatus) {<commit_msg>Clarify 'AddURL' -> 'AddWebSeedURL'.<commit_after>package torrent

import (
	"github.com/nsf/libtorgo/bencode"
	"path/filepath"
	"errors"
	"hash"
	"crypto/sha1"
	"time"
	"sort"
	"io"
	"os"
)

// The Builder type is responsible for .torrent files construction. Just
// instantiate it, call necessary methods and then call the .Build method. While
// waiting for completion you can use 'status' channel to get status reports.
type Builder struct {
	filesmap      map[string]bool
	files         []file
	files_size    int64
	name          string
	piece_length  int64
	pieces        []byte
	private       bool
	announce_list [][]string
	creation_date time.Time
	comment       string
	created_by    string
	encoding      string
	urls          []string
}

// Adds a file to the builder queue. You may add one or more files.
func (b *Builder) AddFile(filename string) {
	if b.filesmap == nil {
		b.filesmap = make(map[string]bool)
	}

	filename, err := filepath.Abs(filename)
	if err != nil {
		panic(err)
	}
	b.filesmap[filename] = true
}

// Defines a name of the future torrent file. For single file torrents it's the
// recommended name of the contained file. For multiple files torrents it's the
// recommended name of the directory in which all of them will be
// stored. Calling this function is not required. In case if no name was
// specified, the builder will try to automatically assign it. It will use the
// name of the file if there is only one file in the queue or it will try to
// find the rightmost common directory of all the queued files and use its name as
// a torrent name. In case if name cannot be assigned automatically, it will use
// "unknown" as a torrent name.
func (b *Builder) SetName(name string) {
	b.name = name
}

// Sets the length of a piece in the torrent file in bytes. The default is
// 256kb.
func (b *Builder) SetPieceLength(length int64) {
	b.piece_length = length
}

// Sets the "private" flag. The default is false.
func (b *Builder) SetPrivate(v bool) {
	b.private = v
}

// Add announce group. TODO: better explanation.
func (b *Builder) AddAnnounceGroup(group []string) {
	b.announce_list = append(b.announce_list, group)
}

// Sets creation date. The default is time.Now() when the .Build method was
// called.
func (b *Builder) SetCreationDate(date time.Time) {
	b.creation_date = date
}

// Sets the comment. The default is no comment.
func (b *Builder) SetComment(comment string) {
	b.comment = comment
}

// Sets the "created by" parameter. The default is "libtorgo".
func (b *Builder) SetCreatedBy(createdby string) {
	b.created_by = createdby
}

// Sets the "encoding" parameter. The default is "UTF-8".
func (b *Builder) SetEncoding(encoding string) {
	b.encoding = encoding
}

func (b *Builder) AddWebSeedURL(url string) {
	b.urls = append(b.urls, url)
}

// Status report structure for Builder.Build method.
type BuilderStatus struct {
	Size int64
	Hashed int64
}

// Builds a torrent file. This function does everything in a separate goroutine
// and uses up to 'nworkers' of goroutines to perform SHA1 hashing. Therefore it
// will return almost immedately. It returns two channels, the first one is for
// completion awaiting, the second one is for getting status reports. You should
// not call any other methods while the builder is working on the torrent file.
func (b *Builder) Build(w io.Writer, nworkers int) (<-chan error, <-chan BuilderStatus) {
{'fraction_non_alphanumeric': 0.09151193633952255, 'fraction_numerical': 0.004715590922487474, 'mean_word_length': 3.4651315789473682, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3469499', 'n_tokens_mistral': 2094, 'n_tokens_neox': 2043, 'n_words': 894}