<commit_before>print("Lade AkWebServerIo ...")

AkWebServerIo = {}

local function dirExists(dir)
    local file = io.open(dir .. "/" .. "tmp.txt", "w")
    io.output(file)
    io.write(EEPVer)
    io.flush()
    io.close(file)
    return true
end

local function existingDirOf(...)
    for _, dir in pairs(...) do
        if pcall(dirExists, dir) then return dir end
    end
    return nil;
end

local ausgabeVerzeichnis = existingDirOf(--{"."}
    { "../LUA/ak/io/exchange", "./LUA/ak/io/exchange" }) or "."
local writing = false

local function fileExists(name)
    local f = io.open(name, "r")
    if f ~= nil then io.close(f) return true else return false end
end

local function writeFile(dateiname, inhalt)
    local file = io.open(dateiname, "w")
    assert(file, "Kann Datei nicht öffnen " .. dateiname)
    file:setvbuf("full", 2 * 1024 * 1024)
    io.output(file)
    io.write(inhalt)
    io.flush()
    io.close(file)
end

---
-- Sendet Inhalte als Ausgabe "type"
-- @param type - Inhaltstyp
-- @param inhalt - Dateiinhalt
function AkWebServerIo.send(type, inhalt, verzeichnis)
    local dir = verzeichnis and verzeichnis or ausgabeVerzeichnis
    if fileExists(dir .. "/ak_out_eep-web-server.on-sync-only")
            and fileExists(dir .. "/ak_out_eep-web-server.lua-is-finished-writing-data") then
        print("SKIPPING - server not ready")
        return
    end

    local dateiname = dir .. "/" .. "ak_out_" .. type .. ".json"
    if not writing then
        writing = true
        if not pcall(writeFile, dateiname, inhalt) then
            print("CANNOT WRITE TO " .. dateiname)
        end
        writing = false
    end

    if fileExists(dir .. "/ak_out_eep-web-server.on-sync-only") then
        writeFile(dir .. "/ak_out_eep-web-server.lua-is-finished-writing-data", "")
    end
end
<commit_msg>Use file:write instead of file:open<commit_after>print("Lade AkWebServerIo ...")

AkWebServerIo = {}

local function dirExists(dir)
    local file = io.open(dir .. "/" .. "tmp.txt", "w")
    file:write(EEPVer)
    file:flush()
    file:close()
    return true
end

local function existingDirOf(...)
    for _, dir in pairs(...) do
        if pcall(dirExists, dir) then return dir end
    end
    return nil;
end

local ausgabeVerzeichnis = existingDirOf(--{"."}
    { "../LUA/ak/io/exchange", "./LUA/ak/io/exchange" }) or "."
local writing = false

local function fileExists(name)
    local f = io.open(name, "r")
    if f ~= nil then io.close(f) return true else return false end
end

local function writeFile(dateiname, inhalt)
    local file = io.open(dateiname, "w")
    assert(file, "Kann Datei nicht öffnen " .. dateiname)
    file:write(inhalt)
    file:flush()
    file:close()
end

---
-- Sendet Inhalte als Ausgabe "type"
-- @param type - Inhaltstyp
-- @param inhalt - Dateiinhalt
function AkWebServerIo.send(type, inhalt, verzeichnis)
    local dir = verzeichnis and verzeichnis or ausgabeVerzeichnis
    if fileExists(dir .. "/ak_out_eep-web-server.on-sync-only")
            and fileExists(dir .. "/ak_out_eep-web-server.lua-is-finished-writing-data") then
        print("SKIPPING - server not ready")
        return
    end

    local dateiname = dir .. "/" .. "ak_out_" .. type .. ".json"
    if not writing then
        writing = true
        if not pcall(writeFile, dateiname, inhalt) then
            print("CANNOT WRITE TO " .. dateiname)
        end
        writing = false
    end

    if fileExists(dir .. "/ak_out_eep-web-server.on-sync-only") then
        writeFile(dir .. "/ak_out_eep-web-server.lua-is-finished-writing-data", "")
    end
end

{'fraction_non_alphanumeric': 0.13697104677060135, 'fraction_numerical': 0.0025055679287305124, 'mean_word_length': 2.6038114343029086, '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': '4091760', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1230, 'n_words': 312}