hxFileManager

hxFileManager is a cross-platform file management library for Haxe with a clean async API backed by a native thread pool. Covers file read/write/append/prepend/truncate, safe atomic writes, raw bytes and Base64 I/O, JSON read/write/patch, folder create/copy/move/delete, recursive listing and deep search (by name, extension, or content), empty-folder cleanup, file and folder watchers, file metadata (size, mtime, MD5, SHA-256), file comparison, unique name generation, temp file/folder creation, batch operations (read, write, copy, move, delete), and HTTP downloads with retry and progress. HttpManager adds GET/POST/PUT/PATCH/DELETE, JSON requests, redirect following, status codes, response headers, internet detection, and retry logic.
https://github.com/HeroEyad/hxFileManager

To install, run:

haxelib install hxFileManager 1.5.0 

See using Haxelib in Haxelib documentation for more information.

README.md

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 pool: init() 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.
  • HTTP: HttpManager provides GET, POST, PUT, PATCH, DELETE, JSON helpers, redirect following, retry logic, progress callbacks, and internet detection.
  • Platform utilities: getAppDataPath, 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

CategoryMethods
Thread Poolinit, dispose, enqueueAsync
ExistencefileExists, folderExists, fileExistsAsync, folderExistsAsync
Read / WritereadFileAsync, readFileBytesAsync, writeFileAsync, writeBytesAsync, appendFileAsync, prependFileAsync, truncateFileAsync, safeWriteAsync, readLinesAsync, writeLinesAsync, readFileBase64Async, writeFileBase64Async
JSONreadJsonAsync, writeJsonAsync, patchJsonAsync
MetadatagetFileMetadataAsync, getFileSizeAsync, getFolderSizeAsync, getLastModifiedAsync
Path HelpersgetFileExtension, getFileName, getFileNameWithoutExt, getParentDir
Copy / Move / DeletecopyFileAsync, copyFolderAsync, moveFileAsync, moveFolderAsync, deletePathAsync, duplicateFileAsync
Folder OpscreateFolderAsync, listFilesAsync, listFilesDeepAsync, listFoldersAsync, countFilesAsync, cleanEmptyFoldersAsync
SearchsearchFilesAsync, searchByExtensionAsync, searchByContentAsync
WatcherswatchFolder, watchFile, stopWatcher
HashinghashFileMd5Async, hashFileSha256Async, compareFilesAsync
BatchbatchReadAsync, batchWriteAsync, batchCopyAsync, batchMoveAsync, batchDeleteAsync
UtilitiesdownloadFileAsync, generateUniqueFileNameAsync, createTempFileAsync, createTempFolderAsync, requestAdmin, getPlatformName, getAppDataPath, logOperation

HttpManager

CategoryMethods
GETrequestText, requestBytes, getJson, getStatusCode, getResponseHeaders, hasBytes
POST / PUT / PATCH / DELETEpostJson, postForm, putJson, patchJson, delete
UtilitiesdownloadTo, 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

Contributors
HeroEyad
Version
1.5.0
Published
4 months ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂