Skip to main content
Glama
docx.ts1.3 kB
import { SupportedFileType } from '@superglue/shared'; import * as mammoth from 'mammoth'; import * as unzipper from 'unzipper'; import { DetectionPriority, FileParsingStrategy } from '../strategy.js'; export class DOCXStrategy implements FileParsingStrategy { readonly fileType = SupportedFileType.DOCX; readonly priority = DetectionPriority.ZIP_BASED_SPECIFIC; async canHandle(buffer: Buffer): Promise<boolean> { // Must be a ZIP file first (PK signature) if (buffer.length < 4) return false; const signature = buffer.subarray(0, 4).toString('hex'); if (signature !== '504b0304') return false; // Check for Word-specific files inside the ZIP try { const zipStream = await unzipper.Open.buffer(buffer); const hasWordSignature = zipStream.files.some(f => f.path === 'word/document.xml' || f.path.startsWith('word/') ); return hasWordSignature; } catch (error) { return false; } } async parse(buffer: Buffer): Promise<any> { return parseDOCX(buffer); } } export async function parseDOCX(buffer: Buffer): Promise<string> { const result = await mammoth.extractRawText({ buffer }); return result.value; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/superglue-ai/superglue'

If you have feedback or need assistance with the MCP directory API, please join our Discord server