<commit_before>#ifndef FILEWRITER_H
#define FILEWRITER_H

//License: Public Domain
//Author: elf
//EMail: <EMAIL>

#include "File.h"

typedef struct FileWriter FileWriter;
typedef I32 (*FileWriteFunction)(FileWriter *pWriter, const Byte *pData, U32 nSize);

struct FileWriter{
    File file;
    U64 nOffset;
    FileWriteFunction Write;
};

static inline Bool FileWriter_SeekToEnd(FileWriter *pWriter);
static inline I32 FileWriter_DefaultWrite(FileWriter *pWriter, const Byte *pData, U32 nSize);

static inline Bool FileWriter_Create(FileWriter *pWriter, const Char *pszPathName){
    if(!File_CreateForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_Open(FileWriter *pWriter, const Char *pszPathName){
    if(!File_OpenForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_Prepare(FileWriter *pWriter, const Char *pszPathName){
    if(!File_PrepareForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_PrepareForAppend(FileWriter *pWriter, const Char *pszPathName){
    if(!File_PrepareForWrite(&pWriter->file, pszPathName))
        return false;

    if(!FileWriter_SeekToEnd(pWriter)){
        File_Close(&pWriter->file);
        return false;
    }

    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline void FileWriter_Close(FileWriter *pWriter){
    File_Close(&pWriter->file);
}

static inline Bool FileWriter_ReadMeta(FileWriter *pWriter){
    return File_ReadMeta(&pWriter->file);
}

static inline void FileWriter_Seek(FileWriter *pWriter, U64 nOffset){
    pWriter->nOffset = nOffset;
}

static inline Bool FileWriter_SeekToEnd(FileWriter *pWriter){
    if(!File_ReadMeta(&pWriter->file))
        return false;

    pWriter->nOffset = pWriter->file.meta.st_size;
    return true;
}

static inline I32 FileWriter_Write(FileWriter *pWriter, const Byte *pData, U32 nSize){
    return pWriter->Write(pWriter, pData, nSize);
}

static inline I32 FileWriter_DefaultWrite(FileWriter *pWriter, const Byte *pData, U32 nSize){
    ssize_t nResult = File_WriteAt(&pWriter->file, pData, nSize, pWriter->nOffset);
    if(nResult == -1)
        return -1;

    pWriter->nOffset += nResult;
    return nResult;
}
#endif // FILEWRITER_H
<commit_msg>Modify FileWriter.h<commit_after>#ifndef FILEWRITER_H
#define FILEWRITER_H

//License: Public Domain
//Author: elf
//EMail: <EMAIL>

#include "File.h"

typedef struct FileWriter FileWriter;
typedef I32 (*FileWriteFunction)(FileWriter *pWriter, const Byte *pData, U32 nSize);

struct FileWriter{
    File file;
    U64 nOffset;
    FileWriteFunction Write;
};

static inline Bool FileWriter_SeekToEnd(FileWriter *pWriter);
static inline I32 FileWriter_DefaultWrite(FileWriter *pWriter, const Byte *pData, U32 nSize);

static inline Bool FileWriter_Create(FileWriter *pWriter, const Char *pszPathName){
    if(!File_CreateForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_Open(FileWriter *pWriter, const Char *pszPathName){
    if(!File_OpenForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_Prepare(FileWriter *pWriter, const Char *pszPathName){
    if(!File_PrepareForWrite(&pWriter->file, pszPathName))
        return false;

    pWriter->nOffset = 0;
    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline Bool FileWriter_PrepareForAppend(FileWriter *pWriter, const Char *pszPathName){
    if(!File_PrepareForWrite(&pWriter->file, pszPathName))
        return false;

    if(!FileWriter_SeekToEnd(pWriter)){
        File_Close(&pWriter->file);
        return false;
    }

    pWriter->Write = FileWriter_DefaultWrite;
    return true;
}

static inline void FileWriter_Close(FileWriter *pWriter){
    File_Close(&pWriter->file);
}

static inline Bool FileWriter_ReadMeta(FileWriter *pWriter){
    return File_ReadMeta(&pWriter->file);
}

static inline void FileWriter_Seek(FileWriter *pWriter, U64 nOffset){
    pWriter->nOffset = nOffset;
}

static inline Bool FileWriter_SeekToEnd(FileWriter *pWriter){
    if(!File_ReadMeta(&pWriter->file))
        return false;

    pWriter->nOffset = pWriter->file.meta.st_size;
    return true;
}

static inline I32 FileWriter_Write(FileWriter *pWriter, const Byte *pData, U32 nSize){
    return pWriter->Write(pWriter, pData, nSize);
}

static inline I32 FileWriter_DefaultWrite(FileWriter *pWriter, const Byte *pData, U32 nSize){
    ssize_t nResult = File_WriteTo(&pWriter->file, pWriter->nOffset, pData, nSize);
    if(nResult == -1)
        return -1;

    pWriter->nOffset += nResult;
    return nResult;
}
#endif // FILEWRITER_H

{'fraction_non_alphanumeric': 0.10459680560966109, 'fraction_numerical': 0.009738994935722634, 'mean_word_length': 4.48025613660619, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '7625442', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1645, 'n_words': 395}