@mediafile-dl/core
v1.0.2
Published
Core MediaFire download library
Readme
@mediafile-dl/core
Core library for resolving MediaFire-style URLs to direct download links and downloading files programmatically.
Install
bun add @mediafile-dl/coreFeatures
- Resolve MediaFire file URLs to direct download links
- Download files with Bun
fetch/Responseprimitives - Override the default MediaFire base URL for mirrors or proxies
- Infer content type from server headers, filename extensions, and magic bytes
Usage
import { downloadFile, resolve } from "@mediafile-dl/core";
const info = await resolve("https://www.mediafire.com/file/xxxxx/file.zip", {
baseUrl: "https://www.mediafire.com",
timeout: 30_000,
});
console.log(info.filename);
console.log(info.url);
console.log(info.size);
console.log(info.contentType);
const response = await downloadFile("https://www.mediafire.com/file/xxxxx/file.zip");
await Bun.write(info.filename, response);API
resolve(url, options?)
Resolves a MediaFire file URL and returns download metadata.
const info = await resolve(url, {
baseUrl: "https://www.mediafire.com",
timeout: 30_000,
headers: {
"User-Agent": "mediafire-lib",
},
});Returns:
{
url: string;
filename: string;
size?: number;
contentType?: string;
}downloadFile(url, options?)
Downloads the resolved file and returns a Response.
const response = await downloadFile(url, {
baseUrl: "https://www.mediafire.com",
timeout: 30_000,
});buildFileUrl(key, baseUrl?)
Builds a MediaFire-style file URL from a file key.
const url = buildFileUrl("abc123");Options
interface MediaFireOptions {
baseUrl?: string;
timeout?: number;
headers?: Record<string, string>;
}Errors
The library throws MediaFireError for expected failures. Check error.code for machine-readable handling.
Common codes include:
TIMEOUTINVALID_URLNOT_FOUNDPARSE_ERRORDOWNLOAD_ERROR
Development
From the repo root:
bun install
bun run --filter @mediafile-dl/core build