<commit_before>package coquelicot

import (
	"os"
)

// Attachment contain info about directory, base mime type and all files saved.
type Attachment struct {
	OriginalFile *OriginalFile
	Dir          *DirManager
	Versions     map[string]FileManager
}

// Function receive root directory, original file, convertion parameters.
// Return Attachment saved.
func Create(storage string, ofile *OriginalFile, converts map[string]string) (*Attachment, error) {
	dm, err := CreateDir(storage, ofile.BaseMime)
	if err != nil {
		return nil, err
	}

	attachment := &Attachment{
		OriginalFile: ofile,
		Dir:          dm,
		Versions:     make(map[string]FileManager),
	}

	if ofile.BaseMime == "image" {
		converts["thumbnail"] = "120x90"
	}
	for version, convert_opt := range converts {
		fm, err := attachment.CreateVersion(version, convert_opt)
		if err != nil {
			return nil, err
		}

		attachment.Versions[version] = fm
	}

	return attachment, os.Remove(attachment.OriginalFile.Filepath)
}

// Directly save single version and return FileManager.
func (attachment *Attachment) CreateVersion(version string, convert string) (FileManager, error) {
	fm := NewFileManager(attachment.Dir, attachment.OriginalFile.BaseMime, version)<commit_msg>Do not generate thumbnail unless -convert flag set<commit_after>package coquelicot

import (
	"os"
)

// Attachment contain info about directory, base mime type and all files saved.
type Attachment struct {
	OriginalFile *OriginalFile
	Dir          *DirManager
	Versions     map[string]FileManager
}

// Function receive root directory, original file, convertion parameters.
// Return Attachment saved.
func Create(storage string, ofile *OriginalFile, converts map[string]string) (*Attachment, error) {
	dm, err := CreateDir(storage, ofile.BaseMime)
	if err != nil {
		return nil, err
	}

	attachment := &Attachment{
		OriginalFile: ofile,
		Dir:          dm,
		Versions:     make(map[string]FileManager),
	}

	if ofile.BaseMime == "image" {
		converts["thumbnail"] = "120x90"
	}

	makeVersion := func(a *Attachment, version, convert string) error {
		fm, err := attachment.CreateVersion(version, convert)
		if err != nil {
			return err
		}
		attachment.Versions[version] = fm
		return nil
	}

	if err := makeVersion(attachment, "original", ""); err != nil {
		return nil, err
	}

	if makeThumbnail {
		if err := makeVersion(attachment, "thumbnail", converts["thumbnail"]); err != nil {
			return nil, err
		}
	}

	return attachment, os.Remove(attachment.OriginalFile.Filepath)
}

// Directly save single version and return FileManager.
func (attachment *Attachment) CreateVersion(version string, convert string) (FileManager, error) {
	fm := NewFileManager(attachment.Dir, attachment.OriginalFile.BaseMime, version)
{'fraction_non_alphanumeric': 0.10763636363636364, 'fraction_numerical': 0.0036363636363636364, 'mean_word_length': 4.300578034682081, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2428632', 'n_tokens_mistral': 871, 'n_tokens_neox': 825, 'n_words': 246}