Extracting Text and Decrypting Office Documents Using Web Workers
Key point
This article introduces how to use Web Workers to parallelize text extraction and decryption of Office documents, preventing UI frame drops and improving performance.
Details
To overcome the single-threaded limitations of JavaScript, this article covers how to use Web Workers to parallelize text extraction and decryption for Office documents (such as doc, docx, and hwp). By distributing binary file handling and complex calculations through message communication between the main thread and Workers, it prevents UI rendering delays.
Performance test results show that when converting 500 files without Web Workers, CPU usage saturates near 100%, causing frame drops. However, applying a Worker Pool approach with 4 Workers increases CPU usage to 321%, enabling parallel processing. For converting 10 files, the Non-Worker method took 0.3 seconds, while the Worker method took 0.1 seconds, demonstrating approximately 3x faster speed.
Office file structures are divided into the OLE Compound Binary structure (pre-2007) and the OOXML structure (post-2007). Text is extracted from each via byte-level specifications or by unzipping and parsing XML. For encrypted OOXML files, a decryption key is generated based on information obtained from the encryptedInfo file (mostly using the SHA-512 algorithm), and the encryptedPackage file is decrypted in 4KB chunks to restore the original. This frontend-based processing enables immediate data analysis without server transmission and is useful in environments with privacy constraints.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.