Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🎉 A universal large file upload solution with chunked upload, resumable upload, and instant upload capabilities. | 通用的大文件上传解决方案,支持分片上传、断点续传和秒传功能

License

Notifications You must be signed in to change notification settings

Sunny-117/chunkflow

Repository files navigation

ChunkFlow Logo

ChunkFlow Upload SDK

A Universal Large File Upload Solution

npm version license GitHub stars

English | 简体中文

📖 Documentation


✨ Features

  • 🚀 Smart Upload Strategy - Automatic selection between direct and chunked upload based on file size
  • 📦 Dynamic Chunking - Adaptive chunk size adjustment based on network conditions (similar to TCP slow start)
  • Instant Upload - Hash-based deduplication for instant uploads (秒传)
  • 🔄 Resumable Upload - Continue uploads from where you left off with IndexedDB persistence
  • 🎯 Framework Agnostic - Core layer works with any framework
  • ⚛️ React Support - Hooks and components for React applications
  • 💚 Vue Support - Composables and components for Vue applications
  • �️ Highly Extensible - Plugin system for custom functionality
  • 🔒 Type Safe - Written in TypeScript with full type definitions
  • 🧪 Well Tested - Comprehensive unit and property-based tests

📦 Packages

Core Packages

Client Packages

Server Package

🚀 Quick Start

Installation

# For React projects
pnpm add @chunkflowjs/core @chunkflowjs/upload-client-react

# For Vue projects
pnpm add @chunkflowjs/core @chunkflowjs/upload-client-vue

React Usage

import { UploadProvider, useUpload } from "@chunkflowjs/upload-client-react";
import { createFetchAdapter } from "@chunkflowjs/core";

const adapter = createFetchAdapter({
  baseURL: "http://localhost:3000/api",
});

function App() {
  return (
    <UploadProvider requestAdapter={adapter}>
      <UploadComponent />
    </UploadProvider>
  );
}

function UploadComponent() {
  const { upload, status, progress } = useUpload({
    onSuccess: (fileUrl) => console.log("Upload complete:", fileUrl),
    onError: (error) => console.error("Upload failed:", error),
  });

  return (
    <div>
      <input
        type="file"
        onChange={(e) => {
          const file = e.target.files?.[0];
          if (file) upload(file);
        }}
      />
      <div>Status: {status}</div>
      <div>Progress: {progress.percentage}%</div>
    </div>
  );
}

Vue Usage

<script setup>
  import { useUpload } from "@chunkflowjs/upload-client-vue";

  const { upload, status, progress } = useUpload({
    onSuccess: (fileUrl) => console.log("Upload complete:", fileUrl),
    onError: (error) => console.error("Upload failed:", error),
  });

  const handleFileChange = (event) => {
    const file = event.target.files?.[0];
    if (file) upload(file);
  };
</script>

<template>
  <div>
    <input type="file" @change="handleFileChange" />
    <div>Status: {{ status }}</div>
    <div>Progress: {{ progress.percentage }}%</div>
  </div>
</template>

🏗️ Architecture

ChunkFlow Upload SDK follows a layered architecture:

┌─────────────────────────────────────────────────────────────┐
│                     Applications                             │
│  Playground (Demo) │ Server (Nest.js) │ Website (Docs)      │
└─────────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────────┐
│                     Component Layer                          │
│  React Components │ Vue Components                           │
└─────────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────────┐
│                     Client Adapter Layer                     │
│  React Hooks │ Vue Composables                               │
└─────────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────────┐
│                     Core Layer                               │
│  Upload Manager │ Upload Task │ Plugin System                │
└─────────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────────┐
│                     Shared Layer                             │
│  Event System │ Concurrency │ File Utils │ Storage           │
└─────────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────────┐
│                     Protocol Layer                           │
│  Type Definitions │ API Interfaces                           │
└─────────────────────────────────────────────────────────────┘

📚 Documentation

Full documentation is available at: https://sunny-117.github.io/chunkflow/

🛠️ Development

This project uses a monorepo structure managed by pnpm workspaces and Turbo.

Prerequisites

  • Node.js >= 18.0.0
  • pnpm >= 9.0.0

Setup

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test

# Lint code
pnpm lint

# Format code
pnpm format

Project Structure

chunkflow/
├── packages/              # SDK packages
│   ├── protocol/         # Protocol layer
│   ├── shared/           # Shared utilities
│   ├── core/             # Core upload engine
│   ├── upload-client-react/    # React adapter
│   ├── upload-client-vue/      # Vue adapter
│   ├── upload-component-react/ # React components
│   ├── upload-component-vue/   # Vue components
│   └── upload-server/    # Server SDK
├── apps/                 # Applications
│   ├── server/          # Nest.js server
│   ├── playground/      # Demo application
│   └── website/         # Documentation site
├── pnpm-workspace.yaml  # Workspace configuration
├── turbo.json           # Turbo configuration
└── package.json         # Root package.json

🧪 Testing

The project uses a dual testing approach:

  • Unit Tests - Test specific examples and edge cases
  • Property-Based Tests - Test universal properties across random inputs using fast-check
# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test -- --coverage

🤝 Contributing

Contributions are welcome! Please read our contributing guidelines before submitting a PR.

📄 License

MIT © Sunny-117

🙏 Acknowledgments


Made with ❤️ by Sunny-117

⭐ Star us on GitHub

About

🎉 A universal large file upload solution with chunked upload, resumable upload, and instant upload capabilities. | 通用的大文件上传解决方案,支持分片上传、断点续传和秒传功能

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published