Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

512 B
Raw Blame
import { splitText } from '../../splitter';
import { type DocumentChunk } from '../../types';
import { loaderConfig } from '../config';

export const DocxLoader = async (fileBlob: Blob | string): Promise<DocumentChunk[]> => {
  const mammoth = await import('mammoth');

  const buffer =
    typeof fileBlob === 'string'
      ? Buffer.from(fileBlob)
      : Buffer.from(await fileBlob.arrayBuffer());

  const result = await mammoth.extractRawText({ buffer });
  return splitText(result.value, loaderConfig);
};