### CLI Usage Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Instructions on how to install and use the DeCompressRTF package as a command-line tool. ```APIDOC ## CLI Usage ### Description The package includes a command-line interface for quick decompression of RTF binary files. The CLI uses the commander package and accepts a binary file path as input, outputting the decompressed RTF content to stdout. ### Installation ```bash npm install -g @kenjiuno/decompressrtf ``` ### Usage ```bash # Decompress a binary file containing compressed RTF data node cli.js decompress __substg1.0_10090102 # Output can be redirected to a file node cli.js decompress __substg1.0_10090102 > output.rtf ``` ``` -------------------------------- ### TypeScript Integration Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Example demonstrating how to use the decompressRTF function within a TypeScript project, including type definitions and error handling. ```APIDOC ## TypeScript Integration ### Description The library is written in TypeScript and exports proper type definitions. The decompressRTF function accepts a `number[]` and returns a `number[]`, making it straightforward to integrate into TypeScript projects. ### Example ```typescript import { decompressRTF } from '@kenjiuno/decompressrtf'; import * as fs from 'fs'; function extractRtfFromMsg(binaryPath: string): string { // Read the compressed RTF stream from MSG file const inputBuffer = fs.readFileSync(binaryPath); // Convert to number array as required by the API const inputArray: number[] = Array.prototype.slice.call(inputBuffer, 0); // Decompress - throws Error if input is invalid // - "At least 16 bytes" if input is too short // - "Either COMPRESSED or UNCOMPRESSED" if magic number is invalid const outputArray: number[] = decompressRTF(inputArray); // Convert back to string return Buffer.from(outputArray).toString('utf8'); } // Usage try { const rtf = extractRtfFromMsg('./test/__substg1.0_10090102'); console.log(rtf); } catch (error) { console.error('Failed to decompress:', error.message); } ``` ``` -------------------------------- ### CLI Usage for DecompressRTF Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Installs and uses the DeCompressRTF package globally via npm to decompress RTF binary files from the command line. The output can be redirected to a file. ```bash # Install globally npm install -g @kenjiuno/decompressrtf # Decompress a binary file containing compressed RTF data node cli.js decompress __substg1.0_10090102 # Output can be redirected to a file node cli.js decompress __substg1.0_10090102 > output.rtf ``` -------------------------------- ### Integrate DecompressRTF in TypeScript Projects Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Demonstrates how to use the decompressRTF function within a TypeScript project, including type definitions and error handling for invalid input. The function accepts and returns number arrays. ```typescript import { decompressRTF } from '@kenjiuno/decompressrtf'; import * as fs from 'fs'; function extractRtfFromMsg(binaryPath: string): string { // Read the compressed RTF stream from MSG file const inputBuffer = fs.readFileSync(binaryPath); // Convert to number array as required by the API const inputArray: number[] = Array.prototype.slice.call(inputBuffer, 0); // Decompress - throws Error if input is invalid // - "At least 16 bytes" if input is too short // - "Either COMPRESSED or UNCOMPRESSED" if magic number is invalid const outputArray: number[] = decompressRTF(inputArray); // Convert back to string return Buffer.from(outputArray).toString('utf8'); } // Usage try { const rtf = extractRtfFromMsg('./test/__substg1.0_10090102'); console.log(rtf); } catch (error) { console.error('Failed to decompress:', error.message); } ``` -------------------------------- ### Error Handling Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Details on the error handling mechanisms implemented in the decompressRTF function, including common error types and how to handle them. ```APIDOC ## Error Handling ### Description The decompressRTF function validates input data and throws descriptive errors for invalid inputs. Proper error handling ensures robust integration when processing MSG files that may contain malformed or incomplete RTF data. ### Common Errors - **Input data too short**: Thrown when the input data is less than 16 bytes. - **Invalid magic number**: Thrown when the input data does not start with a recognized compressed or uncompressed magic number (`0x75465A4C` or `0x414C454D`). ### Example ```javascript const { decompressRTF } = require('@kenjiuno/decompressrtf'); function safeDecompress(data) { try { // Input must be at least 16 bytes (header size) if (!data || data.length < 16) { throw new Error('Input data too short'); } const inputArray = Array.from(data); const result = decompressRTF(inputArray); return { success: true, data: Buffer.from(result).toString('utf8') }; } catch (error) { // Possible errors: // - "At least 16 bytes" - input too short // - "Either COMPRESSED or UNCOMPRESSED" - invalid compression type return { success: false, error: error.message }; } } // Example with invalid data const result = safeDecompress(Buffer.from([0x00, 0x01, 0x02])); console.log(result); // { success: false, error: 'At least 16 bytes' } ``` ``` -------------------------------- ### Decompress RTF Data from MSG File in JavaScript Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Reads compressed RTF binary data from an Outlook MSG file stream, converts it to a number array, decompresses it using decompressRTF, and outputs the RTF content as a string or saves it to a file. Requires 'fs' module for file operations. ```javascript const fs = require('fs'); const { decompressRTF } = require('@kenjiuno/decompressrtf'); // Read compressed RTF binary data from an Outlook MSG file stream // The '__substg1.0_10090102' stream contains PR_RTF_COMPRESSED property const compressedData = fs.readFileSync('__substg1.0_10090102'); // Convert Buffer to number array and decompress const inputArray = Array.prototype.slice.call(compressedData, 0); const decompressedArray = decompressRTF(inputArray); // Convert result to string and display RTF content const rtfContent = Buffer.from(decompressedArray).toString('utf8'); console.log(rtfContent); // Output: {\rtf1\ansi\ansicpg932\fromhtml1 \fbidis \deff0{\fonttbl... // Save decompressed RTF to file fs.writeFileSync('output.rtf', Buffer.from(decompressedArray)); ``` -------------------------------- ### Decompress RTF Content in JavaScript Source: https://github.com/hiraokahypertools/decompressrtf/blob/master/README.md Use this snippet to decompress RTF content from a file. It requires the 'fs' module for file reading and the 'decompressRTF' function from the package. The decompressed output is a byte array that can be converted to a string. ```javascript const fs = require('fs'); const { decompressRTF } = require('@kenjiuno/decompressrtf'); const inputArray = fs.readFileSync('test/__substg1.0_10090102'); const outputArray = decompressRTF(inputArray); console.log(Buffer.from(outputArray).toString("ascii")); ``` -------------------------------- ### Robust Error Handling for RTF Decompression Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt Provides a safe wrapper function for decompressRTF that validates input data length and handles potential errors during decompression, returning a success status and either the decompressed data or an error message. ```javascript const { decompressRTF } = require('@kenjiuno/decompressrtf'); function safeDecompress(data) { try { // Input must be at least 16 bytes (header size) if (!data || data.length < 16) { throw new Error('Input data too short'); } const inputArray = Array.from(data); const result = decompressRTF(inputArray); return { success: true, data: Buffer.from(result).toString('utf8') }; } catch (error) { // Possible errors: // - "At least 16 bytes" - input too short // - "Either COMPRESSED or UNCOMPRESSED" - invalid compression type return { success: false, error: error.message }; } } // Example with invalid data const result = safeDecompress(Buffer.from([0x00, 0x01, 0x02])); console.log(result); // { success: false, error: 'At least 16 bytes' } ``` -------------------------------- ### DecompressRTF Function Source: https://context7.com/hiraokahypertools/decompressrtf/llms.txt The main JavaScript function to decompress RTF data. It accepts a number array and returns the decompressed RTF content as a number array. It automatically handles both compressed and uncompressed RTF data. ```APIDOC ## decompressRTF ### Description The main function that decompresses PR_RTF_COMPRESSED data from Outlook MSG files. It takes a number array representing the raw binary data from the `__substg1.0_10090102` stream and returns the decompressed RTF content as a number array. The function automatically detects whether the input is compressed (magic number `0x75465A4C`) or uncompressed (magic number `0x414C454D`) and processes accordingly. ### Method `decompressRTF(inputArray: number[]): number[]` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const fs = require('fs'); const { decompressRTF } = require('@kenjiuno/decompressrtf'); // Read compressed RTF binary data from an Outlook MSG file stream // The '__substg1.0_10090102' stream contains PR_RTF_COMPRESSED property const compressedData = fs.readFileSync('__substg1.0_10090102'); // Convert Buffer to number array and decompress const inputArray = Array.prototype.slice.call(compressedData, 0); const decompressedArray = decompressRTF(inputArray); // Convert result to string and display RTF content const rtfContent = Buffer.from(decompressedArray).toString('utf8'); console.log(rtfContent); // Output: {\rtf1\ansi\ansicpg932\fromhtml1 \fbidis \deff0{\fonttbl... // Save decompressed RTF to file fs.writeFileSync('output.rtf', Buffer.from(decompressedArray)); ``` ### Response #### Success Response (200) - **decompressedArray** (number[]) - The decompressed RTF content as a number array. #### Response Example ```json // Example output as a number array (truncated for brevity) [123, 92, 114, 116, 102, 49, 92, 97, 110, 115, 105, 92, 97, 110, 115, 105, 99, 112, 103, 57, 50, 50, 92, 102, 114, 111, 109, 104, 116, 109, 108, 49, 32, 92, 102, 98, 105, 100, 105, 115, 32, 92, 100, 101, 102, 102, 48, 123, 92, 102, 111, 110, 116, 116, 98, 108, ...] ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.