Skip to content

HeroEyad/hxFileManager

Repository files navigation

hxFileManager

hxFileManager Logo

Repository Size GitHub Stars License Version Platforms

hxFileManager is a cross-platform file management library for Haxe built on a native worker thread pool. It wraps sys.FileSystem and sys.io.File behind a clean async API so file I/O never blocks your main thread. Every operation has a callback-based async counterpart, and the library ships with JSON helpers, file watching, MD5/SHA-256 hashing, HTTP downloads, and batch operations out of the box.


Features

  • Async thread poolinit() starts N worker threads; all *Async methods run off the main thread and return results via callbacks.
  • Full file I/O — read, write, append, prepend, truncate, safe atomic write, raw bytes, Base64, and line-by-line helpers.
  • JSON — read, write (with pretty-print), and patch-in-place with a transform function.
  • Folder operations — create, copy, move, delete, recursive listing, subdirectory listing, file count, and empty-folder cleanup.
  • Search — find files by name pattern, extension, or content substring.
  • File watching — poll-based watchFile / watchFolder with configurable intervals and cancellation.
  • Hashing & comparison — async MD5, SHA-256, and byte-for-byte file comparison.
  • Batch operations — read, write, copy, move, and delete multiple paths in a single async call.
  • HTTPHttpManager provides GET, POST, PUT, PATCH, DELETE, JSON helpers, redirect following, retry logic, progress callbacks, and internet detection.
  • Platform utilitiesgetAppDataPath, getPlatformName, requestAdmin, generateUniqueFileNameAsync, temp file/folder creation.
  • Metadata — size, last-modified date, extension, filename, and parent directory helpers.
  • Backwards compatible — deprecated sync shims kept under @:deprecated @:noCompletion for smooth migration.

Installation

haxelib install hxFileManager

Or add it to your haxelib.json dependencies:

{
    "dependencies": {
        "hxFileManager": "1.4.0"
    }
}

Quick Start

import hxFileManager.FileManager;
import hxFileManager.HttpManager;

class Main {
    static function main() {
        // Start the thread pool (required before any async call)
        FileManager.init();

        // Write a file asynchronously
        FileManager.writeFileAsync("hello.txt", "Hello, world!", elapsed -> {
            trace("Written in " + elapsed + "s");
        });

        // Read it back
        FileManager.readFileAsync("hello.txt", content -> {
            trace(content);
        });

        // Read and modify a JSON file in one step
        FileManager.patchJsonAsync("config.json", data -> {
            data.version = "1.4.0";
            return data;
        });

        // Download a file with progress
        FileManager.downloadFileAsync(
            "https://example.com/asset.zip",
            "downloads/asset.zip",
            null,
            (received, total) -> trace('$received / $total bytes'),
            () -> trace("Download complete!")
        );

        // Watch a folder for changes
        var watchId = FileManager.watchFolder("assets", () -> {
            trace("assets folder changed!");
        });

        // Stop watching later
        FileManager.stopWatcher(watchId);

        // Shut down cleanly when done
        FileManager.dispose();
    }
}

HttpManager

HttpManager is a standalone HTTP client. All methods are synchronous — wrap them in FileManager.enqueueAsync for non-blocking use.

import hxFileManager.HttpManager;

// GET
var html  = HttpManager.requestText("https://example.com");
var bytes = HttpManager.requestBytes("https://example.com/file.zip");

// POST JSON
HttpManager.postJson("https://api.example.com/scores",
    {player: "Hero", score: 9999},
    null,
    resp -> trace(resp)
);

// PUT / PATCH / DELETE
HttpManager.putJson("https://api.example.com/user/1", {name: "Hero"});
HttpManager.patchJson("https://api.example.com/user/1", {score: 100});
HttpManager.delete("https://api.example.com/user/1");

// Retry + internet check
var bytes = HttpManager.requestWithRetry("https://example.com/file.zip", 5, 1000);
HttpManager.checkInternetAsync(online -> trace(online ? "online" : "offline"));

API Overview

FileManager

Category Methods
Thread Pool init, dispose, enqueueAsync
Existence fileExists, folderExists, fileExistsAsync, folderExistsAsync
Read / Write readFileAsync, readFileBytesAsync, writeFileAsync, writeBytesAsync, appendFileAsync, prependFileAsync, truncateFileAsync, safeWriteAsync, readLinesAsync, writeLinesAsync, readFileBase64Async, writeFileBase64Async
JSON readJsonAsync, writeJsonAsync, patchJsonAsync
Metadata getFileMetadataAsync, getFileSizeAsync, getFolderSizeAsync, getLastModifiedAsync
Path Helpers getFileExtension, getFileName, getFileNameWithoutExt, getParentDir
Copy / Move / Delete copyFileAsync, copyFolderAsync, moveFileAsync, moveFolderAsync, deletePathAsync, duplicateFileAsync
Folder Ops createFolderAsync, listFilesAsync, listFilesDeepAsync, listFoldersAsync, countFilesAsync, cleanEmptyFoldersAsync
Search searchFilesAsync, searchByExtensionAsync, searchByContentAsync
Watchers watchFolder, watchFile, stopWatcher
Hashing hashFileMd5Async, hashFileSha256Async, compareFilesAsync
Batch batchReadAsync, batchWriteAsync, batchCopyAsync, batchMoveAsync, batchDeleteAsync
Utilities downloadFileAsync, generateUniqueFileNameAsync, createTempFileAsync, createTempFolderAsync, requestAdmin, getPlatformName, getAppDataPath, logOperation

HttpManager

Category Methods
GET requestText, requestBytes, getJson, getStatusCode, getResponseHeaders, hasBytes
POST / PUT / PATCH / DELETE postJson, postForm, putJson, patchJson, delete
Utilities downloadTo, requestWithRetry, checkInternet, checkInternetAsync

Migration from older versions

Sync methods from earlier versions (createFile, readFile, copyFile, etc.) are still present under @:deprecated @:noCompletion so existing code compiles without changes. They will be removed in a future major version. Replace them with their *Async equivalents when possible.


Contributors


License

MIT — see LICENSE for details.


Links

About

A library designed for file management tasks in Haxe.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages