### Start Expo Example App Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Starts the Metro server for the Expo example app. ```sh yarn example:expo start ``` -------------------------------- ### Start Bare Example App Packager Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Starts the Metro server for the bare React Native example app to test your changes. ```sh yarn example:bare start ``` -------------------------------- ### Install Dependencies Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Run this command in the root directory to install all required project dependencies. ```sh yarn ``` -------------------------------- ### Run Bare Example App on iOS Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Builds and runs the bare example app on an iOS simulator or device. ```sh yarn example:bare ios ``` -------------------------------- ### Start Expo Development Server Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/expo/README.md Use this command to start the Expo development server and run your application. ```bash npx expo start ``` -------------------------------- ### Download File Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Shows how to download a file from a URL with progress tracking using the download() function. ```javascript import { download } from 'react-native-compressor'; const downloadedFilePath = await download( 'YOUR_URL', 'path/to/save/file.txt', // Optional path to save the file { // progress: (progress) => { // console.log('Download Progress: ' + progress); // }, } ); console.log(downloadedFilePath); // path to the downloaded file ``` -------------------------------- ### Run Bare Example App on Android Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Builds and runs the bare example app on an Android device or emulator. ```sh yarn example:bare android ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/expo/README.md Run this command to install all necessary packages for your Expo project. ```bash npm install ``` -------------------------------- ### Create Video Thumbnail Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Demonstrates how to create a thumbnail image from a video file using createVideoThumbnail(). ```javascript import { createVideoThumbnail } from 'react-native-compressor'; const thumbnailPath = await createVideoThumbnail('path/to/video.mp4', { // size: 1080, // width of the thumbnail // format: 'jpg', // 'jpg' or 'png' // quality: 0.9, // 0.1 - 0.9 // position: 0, // time in seconds from which to take the screenshot }); console.log(thumbnailPath); // path to the thumbnail image ``` -------------------------------- ### Install React Native Compressor Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Install the package using Yarn. ```sh yarn add react-native-compressor ``` -------------------------------- ### Clear Cache Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Shows how to clear the cache used by the compressor library, freeing up disk space. ```javascript import { clearCache } from 'react-native-compressor'; await clearCache(); ``` -------------------------------- ### Audio Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Shows how to compress an audio file using the Audio.compress() function, with options for quality presets and custom parameters. ```javascript import { Audio } from 'react-native-compressor'; const compressedAudio = await Audio.compress( 'path/to/audio.mp3', { // quality: 'low' | 'medium' | 'high' // bitrate: 128000, // 128kbps // sampleRate: 44100, // 44.1kHz // channels: 2, // stereo // downloadσετε: true // default is true } ); console.log(compressedAudio); // base64 or path ``` -------------------------------- ### Background Upload Examples Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Demonstrates binary and multipart uploads using backgroundUpload. Specify uploadType, httpMethod, and other parameters as needed. ```typescript import { backgroundUpload, UploadType, UploaderHttpMethod } from 'react-native-compressor'; // Binary upload (PUT) — file sent as raw bytes const result1 = await backgroundUpload( 'https://example.com/upload', 'file:///path/to/file.jpg', { uploadType: UploadType.BINARY_CONTENT, httpMethod: UploaderHttpMethod.PUT, mimeType: 'image/jpeg', } ); // Multipart form upload (POST) — file in form data const result2 = await backgroundUpload( 'https://example.com/upload', 'file:///path/to/file.jpg', { uploadType: UploadType.MULTIPART, httpMethod: UploaderHttpMethod.POST, fieldName: 'media', mimeType: 'image/jpeg', parameters: { userId: '123', title: 'My Photo', }, } ); ``` -------------------------------- ### Install React Native Compressor with Expo Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Install the package using Expo. ```sh expo install react-native-compressor ``` -------------------------------- ### Get Real Path Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Obtains the real file system path for a given URI or file path using getRealPath(). ```javascript import { getRealPath } from 'react-native-compressor'; const realPath = await getRealPath('content://media/external/images/media/123'); console.log(realPath); // Actual file system path ``` -------------------------------- ### Get File Size Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Retrieves the size of a file in bytes using getFileSize(). ```javascript import { getFileSize } from 'react-native-compressor'; const fileSize = await getFileSize('path/to/file.txt'); console.log(fileSize); // File size in bytes ``` -------------------------------- ### Background Upload Example (Binary) Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Demonstrates uploading a file in binary format using backgroundUpload(). This is suitable for large files where multipart encoding is not required. ```javascript import { backgroundUpload } from 'react-native-compressor'; const response = await backgroundUpload( 'path/to/file.txt', 'YOUR_URL', { method: 'POST', // 'POST' or 'PUT' // binary: true // default is true } ); console.log(response); // HTTPResponse ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/bare/README.md Start the Metro bundler, the JavaScript build tool for React Native. This command is used from the root of your React Native project. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Video Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Shows how to compress a video file using the Video.compress() function. This function allows for background compression and progress tracking. ```javascript import { Video } from 'react-native-compressor'; const compressedVideo = await Video.compress( 'path/to/video.mp4', { // compressionMethod: 'auto' // 'auto' or 'manual' // bitrate: 1000000, // 1000000 = 1Mbps // fps: 30, // size: 1080, // 1080p // progress: (progress) => { // console.log('Compression Progress: ' + progress); // }, // downloadσετε: true // default is true } ); console.log(compressedVideo); // base64 or path ``` -------------------------------- ### Setting Custom Video Compression Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Examples show how to use Video.compress() with default settings, manual compression including bitrate and max size, skipping small videos, and removing audio. ```typescript import { Video } from 'react-native-compressor'; // Use defaults (auto compression) const result1 = await Video.compress('file:///path/to/video.mp4', {}); // Manual compression with custom bitrate const result2 = await Video.compress('file:///path/to/video.mp4', { compressionMethod: 'manual', bitrate: 2000000, // 2 Mbps maxSize: 720, }); // Skip small videos const result3 = await Video.compress('file:///path/to/video.mp4', { minimumFileSizeForCompress: 50, // Skip videos < 50 MB }); // Remove audio track const result4 = await Video.compress('file:///path/to/video.mp4', { stripAudio: true, }); ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/bare/README.md Install CocoaPods dependencies for iOS development. Run 'bundle install' once to install the Ruby bundler, and 'bundle exec pod install' every time native dependencies are updated. ```sh bundle install bundle exec pod install ``` -------------------------------- ### Activate Background Video Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Enables background video compression, allowing compression to continue even when the app is not in the foreground. ```javascript import { Video } from 'react-native-compressor'; Video.activateBackgroundTask(); ``` -------------------------------- ### Complete Import Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md Imports all available modules, utilities, and enums from the library. Useful for projects that utilize a wide range of functionalities. ```typescript import { Image, Video, Audio, backgroundUpload, cancelUpload, download, getImageMetaData, getVideoMetaData, createVideoThumbnail, clearCache, getRealPath, generateFilePath, getFileSize, UploadType, UploaderHttpMethod, } from 'react-native-compressor'; ``` -------------------------------- ### Background Upload Example (Multipart) Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Shows how to upload a file using multipart encoding with backgroundUpload(). This is useful for sending files along with other form data. ```javascript import { backgroundUpload } from 'react-native-compressor'; const response = await backgroundUpload( 'path/to/file.txt', 'YOUR_URL', { method: 'POST', // binary: false, // default is true // uploadType: 'multipart', // default is 'multipart' // headers: { // 'Content-Type': 'multipart/form-data', // 'Authorization': 'Bearer YOUR_TOKEN' // }, // fields: { // 'key1': 'value1', // 'key2': 'value2' // } } ); console.log(response); // HTTPResponse ``` -------------------------------- ### Cancel Upload Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Demonstrates how to cancel an ongoing upload task using cancelUpload(). Supports all cancellation modes. ```javascript import { cancelUpload } from 'react-native-compressor'; // Assuming an upload task is already running cancelUpload('path/to/file.txt'); ``` -------------------------------- ### Cancel Video Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Demonstrates how to cancel an ongoing video compression task using Video.cancelCompression(). ```javascript import { Video } from 'react-native-compressor'; // Assuming a compression task is already running Video.cancelCompression('path/to/video.mp4'); ``` -------------------------------- ### Named Imports Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md Recommended import pattern to import only the necessary modules and functions, improving bundle size. ```typescript import { Image, Video, Audio, backgroundUpload, download } from 'react-native-compressor'; ``` -------------------------------- ### Image Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Demonstrates how to compress an image using the Image.compress() function. This function handles various input types and offers automatic or manual compression methods. ```javascript import { Image } from 'react-native-compressor'; const compressedImage = await Image.compress( 'path/to/image.jpg', { quality: 0.5, // 0.1 - 0.9 // compressionMethod: 'auto' // 'auto' or 'manual' // downloadσετε: true // default is true } ); console.log(compressedImage); // base64 or path ``` -------------------------------- ### Get Video Metadata Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Retrieves metadata (like duration, dimensions, bitrate, etc.) from a video file using getVideoMetaData(). ```javascript import { getVideoMetaData } from 'react-native-compressor'; const metaData = await getVideoMetaData('path/to/video.mp4'); console.log(metaData); // VideoMetaData object ``` -------------------------------- ### Get Image Metadata Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Retrieves metadata (like dimensions, orientation, etc.) from an image file using getImageMetaData(). ```javascript import { getImageMetaData } from 'react-native-compressor'; const metaData = await getImageMetaData('path/to/image.jpg'); console.log(metaData); // ImageMetaData object ``` -------------------------------- ### Generate File Path Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Generates a unique file path for saving compressed or processed files using generateFilePath(). ```javascript import { generateFilePath } from 'react-native-compressor'; const filePath = generateFilePath('image.jpg'); console.log(filePath); // Generated file path (e.g., '/path/to/cache/image_timestamp.jpg') ``` -------------------------------- ### Default Export Usage Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md Alternative import pattern using the default export to access all modules through a single namespace. ```typescript import Compressor from 'react-native-compressor'; // Usage const imageResult = await Compressor.Image.compress(uri); const videoResult = await Compressor.Video.compress(uri); ``` -------------------------------- ### Build and Run iOS App Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/bare/README.md Build and run your iOS application. This command is used from the root of your React Native project after Metro is running and CocoaPods dependencies are installed. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Cancel Video Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/video-api.md Demonstrates how to start a video compression and then cancel it using a cancellation ID obtained from the getCancellationId callback. Use this when you need to stop an ongoing compression process. ```typescript import { Video } from 'react-native-compressor'; let videoCompressionId = ''; // Start compression Video.compress( 'file:///path/to/video.mp4', { getCancellationId: (id) => { videoCompressionId = id; }, } ); // Cancel after 5 seconds setTimeout(() => { Video.cancelCompression(videoCompressionId); }, 5000); ``` -------------------------------- ### Background Upload Options Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Defines options for background uploads, including upload type (BINARY_CONTENT or MULTIPART), HTTP method, headers, and parameters. It also includes a mechanism to get a cancellation ID. ```typescript export enum UploadType { BINARY_CONTENT = 0, MULTIPART = 1, } export enum UploaderHttpMethod { POST = 'POST', PUT = 'PUT', PATCH = 'PATCH', } export declare type HTTPResponse = { status: number; headers: Record; body: string; }; export declare type HttpMethod = 'POST' | 'PUT' | 'PATCH'; export declare type UploaderOptions = ( | { uploadType?: UploadType.BINARY_CONTENT; mimeType?: string; } | { uploadType: UploadType.MULTIPART; fieldName?: string; mimeType?: string; parameters?: Record; } ) & { headers?: Record; httpMethod?: UploaderHttpMethod; getCancellationId?: (cancellationId: string) => void; }; ``` -------------------------------- ### Get Real Path for Media Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Convert 'content://' URIs (Android) or 'ph://' URIs (iOS) to 'file://' paths. Specify the media type ('video' or 'image'). ```javascript import { getRealPath } from 'react-native-compressor'; const realPath = await getRealPath(fileUri, 'video'); // file://file_path.extension ``` -------------------------------- ### Get Real Path for Media Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Converts platform-specific media URIs (like content:// on Android or ph:// on iOS) to standard file paths. Specify the media type ('video' or 'image') for correct resolution. ```typescript import { getRealPath } from 'react-native-compressor'; // Android content:// URI const filePath = await getRealPath('content://media/external/images/media/123', 'image'); console.log('Real path:', filePath); // file:///storage/emulated/0/DCIM/photo.jpg // iOS photo library URI const videoPath = await getRealPath('ph://uuid', 'video'); console.log('Real path:', videoPath); // file:///var/mobile/.../video.mov ``` -------------------------------- ### Reset Expo Project to Initial State Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/expo/README.md Execute this command to reset your project by moving the starter code to 'app-example' and creating a new blank 'app' directory. ```bash npm run reset-project ``` -------------------------------- ### getImageMetaData Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Retrieves metadata for a given image file. This function can also be used to get metadata for videos. ```APIDOC ## getImageMetaData ### Description Retrieves metadata for a given image file. This function can also be used to get metadata for videos. ### Method `getImageMetaData(path: string)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path of the image or video. ### Response Example ```json { "ImageWidth": 4032, "ImageHeight": 3024, "Orientation": 3, "size": 4127057, "extension": "jpg", "exif":{...} } ``` ``` -------------------------------- ### Setting Custom Image Compression Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Demonstrates how to use Image.compress() with default options, override specific settings, or mix custom values with defaults for image compression. ```typescript import { Image } from 'react-native-compressor'; // Use defaults (auto compression) const result1 = await Image.compress('file:///path/to/image.jpg'); // Override specific options const result2 = await Image.compress('file:///path/to/image.jpg', { compressionMethod: 'manual', maxWidth: 800, quality: 0.7, }); // Mix defaults with custom values const result3 = await Image.compress('file:///path/to/image.jpg', { output: 'png', // All other options use defaults }); ``` -------------------------------- ### Setting Custom Audio Compression Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Illustrates using Audio.compress() with default medium quality, selecting 'low' or 'high' quality presets, and specifying custom bitrate, sample rate, and channel count. ```typescript import { Audio } from 'react-native-compressor'; // Use defaults (medium quality) const result1 = await Audio.compress('file:///path/to/audio.wav'); // Low quality for speech const result2 = await Audio.compress('file:///path/to/audio.wav', { quality: 'low', }); // High quality for music const result3 = await Audio.compress('file:///path/to/audio.wav', { quality: 'high', }); // Custom parameters (overrides quality) const result4 = await Audio.compress('file:///path/to/audio.wav', { bitrate: 96000, // 96 kbps samplerate: 44100, // 44.1 kHz channels: 1, // Mono }); ``` -------------------------------- ### Deactivate Background Video Compression Example Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Disables background video compression, returning to normal foreground processing. ```javascript import { Video } from 'react-native-compressor'; Video.deactivateBackgroundTask(); ``` -------------------------------- ### download() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/README.md Downloads files with progress tracking capabilities. ```APIDOC ## download() ### Description Downloads files with progress tracking capabilities. ### Method (Not specified in source, assumed to be a function call) ### Endpoint (Not applicable, this is an SDK function) ### Parameters (Details not provided in source, refer to utilities-api.md) ### Request Example (Not provided in source) ### Response (Details not provided in source, refer to utilities-api.md) ``` -------------------------------- ### Default Compression Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/audio-api.md Demonstrates the default compression options used by the Audio module when no specific options are provided. The default is 'medium' quality, offering a balance between file size and audio fidelity. ```typescript { quality: 'medium' } ``` -------------------------------- ### File Utilities Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Documentation for various utility functions including background uploads, downloads, thumbnail creation, metadata retrieval, and path manipulation. ```APIDOC ## File Utility Functions ### Description Provides a suite of utility functions for file operations, including uploading files (binary and multipart), cancelling uploads, downloading files, creating video thumbnails, clearing cache, retrieving file metadata, and managing file paths. ### Methods - **backgroundUpload(url, options)** - **cancelUpload(uploadId)** - **download(url, options)** - **createVideoThumbnail(videoPath, options)** - **clearCache()** - **getImageMetaData(imagePath)** - **getVideoMetaData(videoPath)** - **getRealPath(uri)** - **generateFilePath(options)** - **getFileSize(filePath)** ### Endpoint (Not applicable, SDK functions) ### Parameters (Details on `options`, `url`, `uploadId`, `videoPath`, `imagePath`, `filePath`, `uri` in utilities-api.md) ### Request Example ```javascript // Example usage (details in utilities-api.md) backgroundUpload('http://example.com/upload', uploadOptions); download('http://example.com/file.zip', downloadOptions); ``` ### Response (Details on return types and success values for each utility in utilities-api.md) ``` -------------------------------- ### Video Compression Options Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Configure video compression using properties like compressionMethod, maxSize, bitrate, and minimumFileSizeForCompress. The 'auto' compression method is suitable for replicating WhatsApp-like compression. ```javascript compressionMethod: compressionMethod maxSize: number bitrate: number minimumFileSizeForCompress: number ``` -------------------------------- ### Get Image Metadata Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Extract metadata from an image file. The metadata includes dimensions, orientation, size, extension, and EXIF data. ```javascript import { getImageMetaData } from 'react-native-compressor'; const metaData = await getImageMetaData(filePath); ``` ```json { "ImageWidth": 4032, "ImageHeight": 3024, "Orientation": 3, "size": 4127057, "extension": "jpg", "exif":{...} } ``` -------------------------------- ### Get Video Metadata Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Extracts duration, dimensions, and size from a video file. The filePath must be a local video file path. ```typescript import { getVideoMetaData } from 'react-native-compressor'; const metadata = await getVideoMetaData('file:///path/to/video.mp4'); console.log(`Duration: ${metadata.duration} seconds`); console.log(`Resolution: ${metadata.width}x${metadata.height}`); console.log(`Size: ${Math.round(metadata.size / 1024 / 1024)} MB`); ``` -------------------------------- ### Video Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Documentation for Video.compress(), Video.cancelCompression(), Video.activateBackgroundTask(), and Video.deactivateBackgroundTask(). ```APIDOC ## Video Compression Functions ### Description Provides functions to compress videos, manage background compression tasks, and cancel ongoing compressions. Supports various video compression types and progress tracking. ### Methods - **Video.compress(inputPath, options)**: Compresses a video file. - **Video.cancelCompression(id)**: Cancels an ongoing video compression. - **Video.activateBackgroundTask()**: Activates background task mode for video compression. - **Video.deactivateBackgroundTask()**: Deactivates background task mode. ### Endpoint (Not applicable, SDK functions) ### Parameters (Details on `options` and `id` in video-api.md) ### Request Example ```javascript // Example usage (details in video-api.md) Video.compress(videoPath, videoOptions); Video.cancelCompression(compressionId); ``` ### Response (Details on return types and success values in video-api.md) ``` -------------------------------- ### Get Image Metadata Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Extracts EXIF data, dimensions, and size from an image file. Ensure the filePath is a local file path. ```typescript import { getImageMetaData } from 'react-native-compressor'; const metadata = await getImageMetaData('file:///path/to/photo.jpg'); console.log(`Image: ${metadata.ImageWidth}x${metadata.ImageHeight}`); console.log(`Size: ${metadata.size} bytes`); console.log(`Orientation: ${metadata.Orientation}`); console.log('EXIF:', metadata.exif); ``` -------------------------------- ### Basic File Download Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Initiate a file download from a given URL. The function returns a promise that resolves with the local file path once the download is complete. ```typescript import { download } from 'react-native-compressor'; const filePath = await download('https://example.com/large-file.zip'); console.log('Downloaded to:', filePath); ``` -------------------------------- ### Audio Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Documentation for Audio.compress(), including audio compression types and quality presets. ```APIDOC ## Audio.compress() ### Description Compresses an audio file using specified quality presets or custom parameters like bitrate, sample rate, and channels. ### Method (Not specified, likely a JavaScript function call) ### Endpoint (Not applicable, SDK function) ### Parameters (Details on `audioCompresssionType` and custom parameters in audio-api.md) ### Request Example ```javascript // Example usage (details in audio-api.md) Audio.compress(audioPath, audioOptions); ``` ### Response #### Success Response (Details on return type and success values in audio-api.md) #### Response Example (Example response structure in audio-api.md) ``` -------------------------------- ### Create Video Thumbnail Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Generates a thumbnail for a video and saves it to the cache directory. Returns the thumbnail's URI, size, mime type, width, and height. ```javascript createVideoThumbnail( fileUrl: string, options: {header:Object} ): Promise<{ path: string;size: number; mime: string; width: number; height: number; }> ``` -------------------------------- ### Get Video Metadata Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Retrieves metadata for a given video file, including duration, extension, height, size, and width. Requires the file path as input. ```javascript import { getVideoMetaData } from 'react-native-compressor'; const metaData = await getVideoMetaData(filePath); ``` ```json { "duration": 20.11, "extension": "mp4", "height": 1080, "size": 16940.0, "width": 1920 } ``` ```javascript `getVideoMetaData(path: string)` ``` -------------------------------- ### Create Video Thumbnail from Remote URL with Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Generate a thumbnail from a remote video URL, supporting custom HTTP headers for authentication and specifying thumbnail quality. The `quality` option ranges from 0 to 100. ```typescript import { createVideoThumbnail } from 'react-native-compressor'; const thumbnail = await createVideoThumbnail('https://example.com/video.mp4', { headers: { 'Authorization': 'Bearer token', }, quality: 90, }); ``` -------------------------------- ### Download Defaults Configuration Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Defines default options for the download function, including progress callback and progress divider. ```typescript const defaults = { downloadProgress: undefined, // No progress callback progressDivider: 0, // All progress updates }; ``` -------------------------------- ### Get File Size in React Native Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Use `getFileSize` to retrieve the size of a file in bytes, then convert it to megabytes for display. Ensure the file path is correctly formatted. ```typescript import { getFileSize } from 'react-native-compressor'; const sizeStr = await getFileSize('file:///path/to/photo.jpg'); const bytes = parseInt(sizeStr); const mb = bytes / (1024 * 1024); console.log(`File size: ${mb.toFixed(2)} MB`); ``` -------------------------------- ### Run Unit Tests Source: https://github.com/numandev1/react-native-compressor/blob/main/CONTRIBUTING.md Executes the unit tests using Jest. ```sh yarn test ``` -------------------------------- ### Turbo Module Support Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Imports the Video module, which automatically uses Turbo Modules if available. ```typescript // Auto-detected: Uses Turbo Module if available import { Video } from 'react-native-compressor'; ``` -------------------------------- ### Video Thumbnail Defaults Configuration Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Sets default options for creating video thumbnails, such as headers and quality. ```typescript const defaults = { options: { headers: undefined, // No custom headers quality: undefined, // Default thumbnail quality }, }; ``` -------------------------------- ### Audio.compress() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/audio-api.md Compresses an audio file using either preset quality levels or custom audio parameters. It takes a file URI and an optional options object to control the compression process. ```APIDOC ## Audio.compress() ### Description Compresses an audio file using either preset quality levels or custom audio parameters. Supports quality-based and parameters-based compression approaches. ### Method `Audio.compress(url: string, options?: audioCompresssionType): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - File URI of the audio file (e.g., `file:///path/to/audio.wav` or `file:///path/to/audio.mp3`). WAV files are recommended on Android; MP3 is converted to WAV before compression. #### Query Parameters - **options** (audioCompresssionType) - Optional - Compression configuration object. Use either `quality` (preset) or custom parameters (`bitrate`, `samplerate`, `channels`). Defaults to `{ quality: 'medium' }`. ### Options Table (audioCompresssionType) - **quality** (string) - Optional - Preset quality level. Options: 'low', 'medium', 'high'. Defaults to 'medium'. Mutually exclusive with `bitrate`. - **bitrate** (number) - Optional - Target bitrate in bits per second. Range: 64,000–320,000. Overrides `quality` if both are provided. - **samplerate** (number) - Optional - Sample rate in Hz. Range: 44,100–192,000. Common values: 44100, 48000. - **channels** (number) - Optional - Number of audio channels. Typically 1 (mono) or 2 (stereo). ### Return Type `Promise` - Resolves to a file path representing the compressed audio. ### Throws Rejects with an error message if compression fails (e.g., unsupported format, invalid input path, insufficient storage). ### Request Example #### Compress with Quality Preset ```typescript import { Audio } from 'react-native-compressor'; const compressedAudio = await Audio.compress('file:///path/to/audio.wav', { quality: 'medium', }); console.log('Compressed:', compressedAudio); ``` #### Custom Bitrate and Sample Rate ```typescript import { Audio } from 'react-native-compressor'; const result = await Audio.compress('file:///path/to/audio.wav', { bitrate: 128000, // 128 kbps samplerate: 44100, // 44.1 kHz channels: 2, // Stereo }); ``` ### Response #### Success Response - **filePath** (string) - The file path of the compressed audio. #### Response Example ```json { "filePath": "file:///path/to/compressed_audio.wav" } ``` ``` -------------------------------- ### Catching Invalid File Path Error for Image Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/errors.md Handle errors that occur if the provided image file path does not exist, is not readable, or is malformed. This is crucial for ensuring the compression process starts correctly. ```typescript import { Image } from 'react-native-compressor'; try { const result = await Image.compress('file:///nonexistent/path.jpg'); } catch (error: any) { console.error('Compression failed:', error.message); } ``` -------------------------------- ### download() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Downloads a file from a remote URL and provides progress updates. It returns a promise that resolves with the local file path. ```APIDOC ## download() ### Description Downloads a file from a remote URL with optional progress tracking. It returns a promise that resolves to the local file path. ### Method ```typescript download(fileUrl: string, downloadProgress?: (progress: number) => void, progressDivider?: number): Promise ``` ### Parameters #### Path Parameters - **fileUrl** (string) - Required - URL to download (e.g., `https://example.com/file.zip`). - **downloadProgress** ((progress: number) => void) - Optional - Callback fired during download. Progress is 0–100. - **progressDivider** (number) - Optional - Divides progress updates. Use to reduce callback frequency (e.g., 10 fires every 10%). ### Response #### Success Response (200) - **path** (string) - Local file path (e.g., `file:///path/to/downloaded_file`). ### Request Example ```typescript import { download } from 'react-native-compressor'; // Basic Download const filePath = await download('https://example.com/large-file.zip'); console.log('Downloaded to:', filePath); // Download with Progress const filePathWithProgress = await download( 'https://example.com/video.mp4', (progress) => { console.log(`Download progress: ${progress}%`); } ); // Download with Throttled Progress const filePathThrottled = await download( 'https://example.com/file.zip', (progress) => { console.log(`Progress: ${progress}%`); }, 10 // Fire callback every 10% ); ``` ``` -------------------------------- ### Video.activateBackgroundTask() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/README.md Enables background compression for videos on iOS. ```APIDOC ## Video.activateBackgroundTask() ### Description Enables background compression for videos on iOS. ### Method (Not specified in source, assumed to be a function call) ### Endpoint (Not applicable, this is an SDK function) ### Parameters (Details not provided in source, refer to video-api.md) ### Request Example (Not provided in source) ### Response (Details not provided in source, refer to video-api.md) ``` -------------------------------- ### Activate Background Task for Video Compression (iOS) Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/video-api.md Enables background task support for video compression on iOS. Call this before starting compression if you need it to continue when the app is suspended or in the background. Remember to call deactivateBackgroundTask() afterwards. ```typescript import { Video } from 'react-native-compressor'; // Enable background compression await Video.activateBackgroundTask((expiredData) => { console.log('Background task expired:', expiredData); }); // Start compression const result = await Video.compress('file:///path/to/video.mp4', {}); // Disable background task when done await Video.deactivateBackgroundTask(); ``` -------------------------------- ### Image Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/INDEX.txt Documentation for Image.compress() function, including CompressorOptions and input type handling. ```APIDOC ## Image.compress() ### Description Compresses an image using specified options. Handles various input types and supports automatic or manual compression methods. ### Method (Not specified, likely a JavaScript function call) ### Endpoint (Not applicable, SDK function) ### Parameters #### Path Parameters (Not applicable) #### Query Parameters (Not applicable) #### Request Body (Not applicable) ### Request Example ```javascript // Example usage (details in image-api.md) Image.compress(inputPath, options); ``` ### Response #### Success Response (Details on return type and success values in image-api.md) #### Response Example (Example response structure in image-api.md) ``` -------------------------------- ### Audio.compress() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/README.md Compresses WAV/MP3 audio using quality presets or custom settings for bitrate, sample rate, and channels. ```APIDOC ## Audio.compress() ### Description Compresses WAV/MP3 audio using quality presets or custom settings for bitrate, sample rate, and channels. ### Method (Not specified in source, assumed to be a function call) ### Endpoint (Not applicable, this is an SDK function) ### Parameters (Details not provided in source, refer to audio-api.md) ### Request Example (Not provided in source) ### Response (Details not provided in source, refer to audio-api.md) ``` -------------------------------- ### backgroundUpload Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Initiates a background upload with progress tracking and cancellation support via AbortController. ```APIDOC ## backgroundUpload ### Description Initiates a background upload for a given file. It supports progress tracking and can be cancelled using an AbortController signal. ### Method `backgroundUpload(url: string, fileUrl: string, options?: UploadOptions, onProgress?: (written: number, total: number) => void, signal?: AbortSignal): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - The URL to upload to. - **fileUrl** (string) - Required - The local URI of the file to upload. #### Query Parameters - **options** (UploadOptions) - Optional - Configuration for the upload, including `httpMethod` and `getCancellationId`. - **httpMethod** (string) - Optional - The HTTP method to use for the upload (e.g., 'PUT'). - **getCancellationId** (function) - Optional - A callback function that receives the cancellation ID for the upload. - **onProgress** (function) - Optional - A callback function that reports upload progress (`written` bytes, `total` bytes). - **signal** (AbortSignal) - Optional - An AbortSignal to cancel the upload. ### Usage Examples ```javascript // Upload with progress and cancellation ID let videoId='' const uploadResult = await backgroundUpload( url, fileUrl, { httpMethod: 'PUT', getCancellationId: (cancellationId) =>(videoId = cancellationId) }, (written, total) => { console.log(written, total); } ); // Upload with AbortController for cancellation const abortSignalRef = useRef(new AbortController()); const uploadResult = await backgroundUpload( url, fileUrl, { httpMethod: 'PUT' }, (written, total) => { console.log(written, total); }, abortSignalRef.current.signal ); // To cancel the upload: abortSignalRef.current?.abort(); ``` ``` -------------------------------- ### Utilities Module Functions Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md Provides supporting functions for uploads, downloads, metadata extraction, and file operations. Use these for background uploads, file downloads, thumbnail generation, and metadata retrieval. ```typescript import { backgroundUpload, download, createVideoThumbnail, getImageMetaData, getVideoMetaData, getRealPath, generateFilePath, getFileSize, clearCache, cancelUpload } from 'react-native-compressor'; // Example usage: // const uploadResult = await backgroundUpload(fileUri, url); // const downloadedFileUri = await download(fileUrl); // const thumbnailUri = await createVideoThumbnail(videoUri); // const metaData = await getImageMetaData(imageUri); // const realPath = await getRealPath(platformUri); // const fileSize = await getFileSize(fileUri); // await clearCache(); // await cancelUpload(uploadId); ``` -------------------------------- ### Import Video Module Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/video-api.md Import the Video module from the react-native-compressor library. ```typescript import { Video } from 'react-native-compressor'; ``` -------------------------------- ### Import Utilities Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Import all necessary utilities from the react-native-compressor library. ```typescript import { backgroundUpload, cancelUpload, download, createVideoThumbnail, clearCache, getImageMetaData, getVideoMetaData, getRealPath, generateFilePath, getFileSize, UploadType, UploaderHttpMethod, } from 'react-native-compressor'; ``` -------------------------------- ### backgroundUpload() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/README.md Uploads files with progress tracking capabilities. ```APIDOC ## backgroundUpload() ### Description Uploads files with progress tracking capabilities. ### Method (Not specified in source, assumed to be a function call) ### Endpoint (Not applicable, this is an SDK function) ### Parameters (Details not provided in source, refer to utilities-api.md) ### Request Example (Not provided in source) ### Response (Details not provided in source, refer to utilities-api.md) ``` -------------------------------- ### Create Video Thumbnail from Local File Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Generate a thumbnail image from a local video file. The function returns a promise with details about the generated thumbnail, including its path and dimensions. ```typescript import { createVideoThumbnail } from 'react-native-compressor'; const thumbnail = await createVideoThumbnail('file:///path/to/video.mp4'); console.log('Thumbnail path:', thumbnail.path); console.log('Dimensions:', `${thumbnail.width}x${thumbnail.height}`); ``` -------------------------------- ### compress (video) Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Compresses a video file. Supports manual compression with bitrate control or automatic compression similar to WhatsApp. Options include compression method, download progress callback, progress divider, maximum size, bitrate, and minimum file size for compression. ```APIDOC ## compress (video) ### Description Compresses a video file. Supports manual compression with bitrate control or automatic compression similar to WhatsApp. Options include compression method, download progress callback, progress divider, maximum size, bitrate, and minimum file size for compression. ### Method `compress(url: string, options?: videoCompresssionType): Promise` ### Parameters #### Request Body (options) - **compressionMethod** (string) - Optional - Defines the Compression Method. Can be `manual` or `auto`. - **downloadProgress** (function) - Optional - Callback triggered when an image URL is passed from the server. - **progressDivider** (number) - Optional - Used with `downloadProgress` or `onProgress`. - **maxSize** (number) - Optional - The maximum size (height for portrait, width for landscape). - **bitrate** (number) - Optional - Bitrate of the video, affects video size. Does not work if `compressionMethod` is `auto`. - **minimumFileSizeForCompress** (number) - Optional - Minimum file size offset to prevent compression of small files. ``` -------------------------------- ### File Upload Configuration Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/types.md Defines the configuration options for file uploads, supporting both binary content and multipart form data. Includes common fields like headers and HTTP method, as well as type-specific fields. ```typescript type UploaderOptions = ( | { uploadType?: UploadType.BINARY_CONTENT; mimeType?: string; } | { uploadType: UploadType.MULTIPART; fieldName?: string; mimeType?: string; parameters?: Record; } ) & { headers?: Record; httpMethod?: UploaderHttpMethod | HttpMethod; getCancellationId?: (cancellationId: string) => void; }; ``` -------------------------------- ### Video.activateBackgroundTask Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Enables background task mode for video compression, allowing compression to continue when the app is in the background. ```APIDOC ## Video.activateBackgroundTask ### Description Activates a background task mode, which is necessary for compressing videos while the application is not in the foreground. An optional callback can be provided to handle events when the background task expires. ### Method `activateBackgroundTask(onExpired?: (data: any) => void): Promise` ### Parameters #### Query Parameters - **onExpired** (function) - Optional - A callback function that is executed when the background task expires. ### Response #### Success Response - **result** (any) - The result of activating the background task. ### Usage Example ```javascript await Video.activateBackgroundTask((data) => { console.log('Background task expired:', data); }); ``` ``` -------------------------------- ### Download and Compress Image Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md Downloads an image from a URL, tracks download progress, and then compresses the downloaded image. ```typescript import { download, Image } from 'react-native-compressor'; async function downloadAndCompress(imageUrl: string) { // Step 1: Download const localPath = await download( imageUrl, (progress) => { console.log(`Downloaded: ${progress}%`); } ); // Step 2: Compress const compressed = await Image.compress(localPath); return compressed; } ``` -------------------------------- ### Source File Structure Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/api-overview.md This snippet shows the directory structure of the react-native-compressor library, illustrating the organization of modules for image, video, audio compression, utilities, and native interface definitions. ```tree src/ ├── index.tsx # Main export point ├── Main.tsx # Native module initialization ├── Image/ │ └── index.tsx # Image compression ├── Video/ │ └── index.tsx # Video compression ├── Audio/ │ └── index.tsx # Audio compression ├── Spec/ │ └── NativeCompressor.ts # TypeScript Native Module interface ├── utils/ │ ├── index.tsx # Metadata, file utilities │ ├── Uploader.tsx # Background upload │ ├── Downloader.tsx # File download │ ├── helpers.ts # UUID generation │ └── index.tsx # Re-exports and defaults └── expo-plugin/ └── compressor.ts # Expo plugin configuration ``` -------------------------------- ### createVideoThumbnail() Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/README.md Generates a thumbnail image from a video file. ```APIDOC ## createVideoThumbnail() ### Description Generates a thumbnail image from a video file. ### Method (Not specified in source, assumed to be a function call) ### Endpoint (Not applicable, this is an SDK function) ### Parameters (Details not provided in source, refer to utilities-api.md) ### Request Example (Not provided in source) ### Response (Details not provided in source, refer to utilities-api.md) ``` -------------------------------- ### Import Audio Module Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/audio-api.md Import the Audio module from the react-native-compressor library to access its functionalities. ```typescript import { Audio } from 'react-native-compressor'; ``` -------------------------------- ### Video Compression Default Options Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md These defaults apply when Video.compress() is called without explicit options. They include compression method, maximum size, minimum file size for compression, and audio handling. ```typescript const defaults: videoCompresssionType = { compressionMethod: 'auto', // WhatsApp-like compression maxSize: 640, // pixels (width or height) minimumFileSizeForCompress: 0, // MB (no minimum) stripAudio: false, // Keep audio // bitrate: undefined (ignored in 'auto' mode) // getCancellationId: undefined // downloadProgress: undefined // progressDivider: undefined }; ``` -------------------------------- ### WhatsApp-Like Video Compression Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/configuration.md Use 'auto' compression method for videos to match WhatsApp's behavior. This is the default setting. ```typescript const videoResult = await Video.compress(videoUri, { compressionMethod: 'auto', // Default }); ``` -------------------------------- ### Build and Run Android App Source: https://github.com/numandev1/react-native-compressor/blob/main/examples/bare/README.md Build and run your Android application. This command is used from the root of your React Native project after Metro is running. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### File Download with Progress Tracking Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/utilities-api.md Download a file and receive progress updates via a callback function. The callback receives a number representing the download progress from 0 to 100. ```typescript import { download } from 'react-native-compressor'; const filePath = await download( 'https://example.com/video.mp4', (progress) => { console.log(`Download progress: ${progress}%`); } ); ``` -------------------------------- ### Automatic Compression from Local File Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/video-api.md Compresses a local video file using the default 'auto' compression method. Includes progress callbacks. ```typescript import { Video } from 'react-native-compressor'; const compressedVideoUri = await Video.compress('file:///storage/emulated/0/DCIM/video.mp4', {}, (progress) => { console.log(`Compression progress: ${progress}%`); }); console.log('Compressed:', compressedVideoUri); ``` -------------------------------- ### Manual Image Compression with Custom Parameters Source: https://github.com/numandev1/react-native-compressor/blob/main/_autodocs/image-api.md Compresses an image from a file URI with specified manual compression settings, including maximum dimensions and quality. ```typescript import { Image } from 'react-native-compressor'; const result = await Image.compress('file:///path/to/image.jpg', { compressionMethod: 'manual', maxWidth: 800, maxHeight: 800, quality: 0.7, }); ``` -------------------------------- ### download Source: https://github.com/numandev1/react-native-compressor/blob/main/README.md Downloads a file from a given URL and provides progress updates. ```APIDOC ## download ### Description Downloads a file from a specified URL. The function provides progress updates during the download process. ### Method `download(url: string, onProgress?: (progress: number) => void): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - The URL of the file to download. #### Query Parameters - **onProgress** (function) - Optional - A callback function that reports download progress as a number. ### Response #### Success Response - **downloadFileUrl** (string) - The local URI of the downloaded file. ### Usage Example ```javascript const downloadFileUrl = await download(url, (progress) => { console.log('downloadProgress: ', progress); }); ``` ```