A method, apparatus, and related products for multi-threaded file transfer using Electron based on front-end preprocessing.

By introducing front-end preprocessing and thread pool-based sharding in Electron file transfer, the problem of excessive main process computation load was solved, file differentiation was achieved, and transfer efficiency and fault tolerance were improved.

CN123123359APending Publication Date: 2026-11-17CSC FINANCIAL CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611481375.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-22
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In existing Electron file transfer solutions, the main process's computational load is too heavy, causing page lag. Furthermore, there is no logic to distinguish between large and small files during transfer, resulting in low efficiency for single-threaded serial transfer, especially for large or batch file transfers, and poor fault tolerance.

Method used

By preprocessing at the front end to generate a transmission draft and dividing it into fragmented transmission tasks, the fragmented transmission tasks are executed using a thread pool. The main process is only responsible for task distribution and management, which reduces the computational load. The size of the thread pool is dynamically adjusted according to CPU and memory resources to achieve differentiated file transmission.

Benefits of technology

It effectively reduces the main process's computational load, avoids page lag, improves file transfer efficiency and fault tolerance, and adapts to the transfer needs of files of different sizes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123359A_ABST
    Figure CN123123359A_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, and related products for multi-threaded file transfer using Electron based on front-end preprocessing, relating to the field of data processing technology. The method includes: a front-end performing preprocessing operations on the file to be transferred to obtain a transfer draft including a first fingerprint; the front-end determining at least one fragmented transfer task based on the transfer draft; the main process distributing the at least one fragmented transfer task to at least one worker thread in a thread pool; the at least one worker thread executing the at least one fragmented transfer task to obtain the target file; and verifying the target file based on the first fingerprint. This application reduces the computational load on the main process and avoids page lag by moving the preprocessing operation to the front-end; and achieves differentiated file transfer by executing fragmented transfer tasks through a thread pool.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to an Electron multi-threaded file transfer method, apparatus and related products based on front-end preprocessing. Background Technology

[0002] With the widespread adoption of Electron (a cross-platform desktop application development framework) in cross-platform desktop applications, file upload and download have become core functions in client-side file management and data synchronization scenarios. In recent years, the integration of multi-threaded parallel computing and front-end preprocessing technologies has driven continuous improvements in file transfer efficiency, but existing solutions still have shortcomings in preprocessing mechanisms, transfer modes, and task management.

[0003] Currently, mainstream Electron file transfer solutions typically place preprocessing logic such as file verification, fragmentation, and parameter configuration in the main process or server. The main process is responsible for both page rendering and process scheduling, and a large amount of computation consumes main thread resources, resulting in page lag and interactive blocking. Moreover, most of them adopt a single-threaded serial transmission mode without distinguishing between large and small file transfer logic. The transfer rate of large files or batch files is low, and a single exception can cause the entire task to be interrupted.

[0004] Therefore, how to reduce the computational load of the main process and achieve differentiated file transmission has become an urgent technical problem to be solved. Summary of the Invention

[0005] In view of the above problems, this application proposes to provide an Electron multi-threaded file transfer method, apparatus, and related products based on front-end preprocessing that overcomes or at least partially solves the above problems. The technical solution is as follows: Firstly, a multi-threaded file transfer method based on front-end preprocessing in Electron is provided, the method comprising: The front end performs preprocessing operations on the file to be transmitted to obtain a transmission draft including the first fingerprint; The front end determines at least one fragment transmission task based on the transmission draft; The main process distributes at least one fragment transfer task to at least one worker thread in the thread pool; At least one worker thread executes at least one fragment transfer task to obtain a target file, which is a complete file obtained based on at least one fragment transfer task; Verify the target file based on the first fingerprint.

[0006] In one possible implementation, the front end determines at least one fragmented transmission task based on the transmission draft, including: If the size of the transmitted draft exceeds the preset fragmentation threshold, the front end will divide the transmitted draft into multiple data fragments. Each data fragment includes a fragmentation number, a byte offset, and a fragmentation hash value. If the size of the transmitted draft is less than or equal to the preset fragmentation threshold, the front end will transmit the draft as a data fragment. At least one fragmentation transmission task corresponds to one data fragment.

[0007] In one possible implementation, before the main process distributes at least one fragmented transfer task to at least one worker thread in the thread pool, it further includes: Create a thread pool based on the number of CPU cores and memory capacity.

[0008] In one possible implementation, at least one worker thread executes at least one fragmented transfer task in parallel to obtain the target file, including: Calculate and output the transmission progress, which indicates the progress of the transmission of the manuscript.

[0009] In one possible implementation, before verifying the target file based on the first fingerprint, the following is also included: In response to a pause command, mark at least one unfinished fragment transmission task in the fragment transmission task as paused, and retain the data corresponding to at least one fragment transmission task; Alternatively, in response to a cancellation command, terminate the network connection of at least one worker thread and clear the data corresponding to at least one fragmented transfer task.

[0010] In one possible implementation, the target file is verified based on the first fingerprint, including: Calculate the second fingerprint of the target file; If the second fingerprint matches the first fingerprint, set the status of the transmitted draft to transmission complete; If the second fingerprint is inconsistent with the first fingerprint, set the status of the transmitted draft to transmission error.

[0011] Secondly, a front-end preprocessing-based Electron multi-threaded file transfer device is provided, the device comprising: The first processing unit is used to perform preprocessing operations on the file to be transmitted at the front end to obtain a transmission draft including the first fingerprint; The second processing unit is used by the front end to determine at least one fragmented transmission task based on the transmission draft. The task scheduling unit is used by the main process to distribute at least one fragmented transmission task to at least one worker thread in the thread pool. The task execution unit is used by at least one worker thread to execute at least one fragmented transfer task to obtain a target file, which is a complete file obtained based on at least one fragmented transfer task; The file verification unit is used to verify the target file based on the first fingerprint.

[0012] Thirdly, an electronic device is provided, comprising a processor and a memory, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the Electron multithreaded file transfer method based on front-end preprocessing as described in any of the preceding claims.

[0013] Fourthly, a storage medium is provided that stores a computer program, wherein the computer program is configured to execute the Electron multi-threaded file transfer method based on front-end preprocessing as described above at runtime.

[0014] Fifthly, a computer program product is provided, including a computer program configured to execute the Electron multithreaded file transfer method based on front-end preprocessing as described above at runtime.

[0015] Using the above technical solutions, the Electron multi-threaded file transfer method, apparatus, and related products based on front-end preprocessing provided in this application embodiment include: the front end performs preprocessing operations on the file to be transferred to obtain a transfer draft including a first fingerprint; the front end determines at least one fragmented transfer task based on the transfer draft; the main process distributes the at least one fragmented transfer task to at least one worker thread in a thread pool; the at least one worker thread executes the at least one fragmented transfer task to obtain the target file; the target file is verified based on the first fingerprint. This application embodiment reduces the computational load of the main process and avoids page lag by placing the preprocessing operation at the front end; and achieves differentiated file transfer by executing the fragmented transfer task through the thread pool. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0017] Figure 1 This paper illustrates a flowchart of an Electron multi-threaded file transfer method based on front-end preprocessing provided in an embodiment of this application. Figure 2 This illustration shows an architecture diagram of a front-end preprocessing Electron multi-threaded file transfer method provided in a specific embodiment of this application; Figure 3This invention illustrates a flowchart of a front-end preprocessing process provided in a specific embodiment of this application. Figure 4 This illustration shows a flowchart of a fragmented transmission task distribution provided in a specific embodiment of this application; Figure 5 This illustration shows a flowchart of a segmented transmission task execution provided in a specific embodiment of this application; Figure 6 This illustration shows a flowchart of a document verification process provided in a specific embodiment of this application; Figure 7 This paper shows a structural diagram of an Electron multi-threaded file transfer device based on front-end preprocessing provided in an embodiment of this application. Figure 8 A structural diagram of an electronic device provided in an embodiment of this application is shown. Detailed Implementation

[0018] Exemplary embodiments of the present application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this application will be thorough and complete, and will fully convey the scope of the present application to those skilled in the art.

[0019] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such use can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the term "comprising" and its variations should be interpreted as open-ended terms meaning "including but not limited to."

[0020] As the Electron framework continues to gain popularity in cross-platform desktop applications, file transfer is gradually covering diverse business scenarios such as large-file batch uploads, offline downloads, and resume downloads. Applications are increasingly demanding higher efficiency, smoother interaction, and better task management capabilities.

[0021] Currently, there are two main types of solutions for Electron file transfer in the industry: The first type is based on centralized processing in the main process. This solution places file verification, fragment calculation, and parameter configuration all in the main process. The main process is responsible for both page rendering and process scheduling. A large amount of preprocessing operations consume the main thread resources, resulting in page lag and interactive blocking. Furthermore, it does not differentiate between file transfer logic of different sizes. Single-threaded serial transmission is extremely slow and has poor fault tolerance when dealing with large or batch files. The second type is based on simple multi-threaded scheduling. Although this solution introduces multi-threaded parallel transmission, it does not combine it with front-end preprocessing data. Thread scheduling is disordered, task allocation is uneven, and thread pools are not adaptively configured according to the device's CPU and memory. This easily leads to thread congestion and duplicate fragment transmission. Moreover, breakpoint resume only records a simple progress and does not retain a complete preprocessing copy. After the transmission is restarted, verification, fragmentation, hash comparison, and other operations need to be re-executed. The amount of redundant computation is large, fragmented files lack unified management, and long-term accumulation occupies local storage space.

[0022] To address the aforementioned technical problems, this application provides an Electron multi-threaded file transfer method based on front-end preprocessing, such as... Figure 1 As shown, this Electron multi-threaded file transfer method based on front-end preprocessing may include the following steps S101 to S105: Step S101: The front end performs a preprocessing operation on the file to be transmitted to obtain a transmission draft including the first fingerprint.

[0023] In one possible implementation, the file to be transferred can be either a file to be uploaded or a file to be downloaded.

[0024] In one possible implementation, the front-end can obtain the basic attribute information of the file to be transmitted through the native file interface and perform compliance verification operations on the file. For example, compliance verification can include file format verification and file size verification. File format verification is completed by comparing the file extension of the file to be transmitted with a preset file extension whitelist. The preset file extension whitelist can cover file formats commonly used in various business scenarios, such as documents, images, audio and video, and code. File size verification is completed by comparing the actual size of the file to be transmitted with a preset file size limit. For files to be transmitted whose format is not within the whitelist, whose size exceeds the preset limit, or whose corruption flag is detected, the corresponding transmission request can be directly intercepted, and the transmission process can be terminated.

[0025] In one possible implementation, after the front end completes the compliance verification of the file to be transmitted, it can calculate the unique hash value of the file to be transmitted as the first fingerprint through a cryptographic hash algorithm. For example, the hash algorithm can be SM3 (SM3 Cryptographic Hash Algorithm) first fingerprint, which is written into the transmission file as the basis for integrity verification.

[0026] In one possible implementation, the front-end can configure multiple transmission parameters in the transmission file. For example, transmission parameters may include at least one of the following: transmission concurrency, timeout threshold, maximum number of retries, server interface address, local storage path, session identifier, file service identifier, or interface format identifier. The configured transmission file can be cached in a local temporary storage area to avoid process delays and response latency caused by dynamically parsing parameters during transmission.

[0027] Step S102: The front end determines at least one fragmented transmission task based on the transmission draft.

[0028] In one possible implementation, the front end synchronizes at least one fragmented transmission task to the main process via the Electron IPC (Inter-Process Communication) channel, and the main process then distributes the subsequent tasks.

[0029] In step S103, the main process distributes at least one fragmented transfer task to at least one worker thread in the thread pool.

[0030] In one possible implementation, the main process can employ a two-level rate limiting mechanism to manage the concurrency of fragmented tasks. The first level controls the total number of concurrent tasks globally, while the second level manages the task queue within the thread pool. The main process can then distribute the fragmented transmission tasks evenly across the worker threads in the thread pool based on the total number of fragmented transmission tasks, task priorities, and the current device load. For example, high-priority files are allocated resources first to avoid thread overload and task backlog.

[0031] In one possible implementation, IPC communication can be divided into request-response classes, progress tracking classes, and general auxiliary classes. For example, the request-response class uses the `ipcRenderer.invoke` (rendering process call) and `ipcMain.handle` (main process handling) patterns to obtain cookies, submit chunk uploads or downloads, cancel tasks, and query thread pool status; the progress tracking class uses the `webContents.send` (web page content sending) and `ipcRenderer.on` (rendering process listening) patterns to push chunk progress and intra-chunk transmission progress in real time; the general auxiliary class is used for auxiliary operations such as setting cookies, session refresh, logging out, and opening directory selection boxes.

[0032] In step S104, at least one worker thread executes at least one fragment transfer task to obtain the target file.

[0033] In one possible implementation, each worker thread introduces network libraries such as undici (a client library) to establish HTTP (HyperText Transfer Protocol) or HTTPS (HyperText Transfer Protocol Secure) transmission sessions and independently executes the fragmented transmission task.

[0034] In one possible implementation, for a chunked transmission task of the upload type, the worker thread reads the data chunk corresponding to the chunked transmission task, adapts the multipart / form-data request format according to the business type, configures the request header, cookie and timeout, and then completes the upload of the corresponding data chunk.

[0035] In one possible implementation, for download-type chunked transmission tasks, the worker thread adapts the JSON (JavaScript Object Notation) request format according to the interface specification, receives the data chunks corresponding to the chunked transmission task, and writes them to the local disk.

[0036] In one possible implementation, the worker thread incorporates network anomaly detection and retry logic, capable of identifying four types of network anomalies: connection reset, connection timeout, connection rejection, and request timeout. Upon detecting a network anomaly, an automatic retry mechanism is triggered, with a maximum retry count of three, and the retry interval is progressively extended using an incremental backoff strategy. If all retries fail, the system automatically switches to serial transmission mode.

[0037] In one possible implementation, after all data fragments have been transmitted, the multiple data fragments are merged to obtain the target file, which is a complete file obtained based on at least one data fragment transmission task.

[0038] Step S105: Verify the target file based on the first fingerprint.

[0039] This embodiment reduces the computational load on the main process and avoids page lag by moving the preprocessing operation to the front end; it also achieves differentiated file transmission by executing the fragmented transmission task through a thread pool.

[0040] This application provides a possible implementation method in which the front end determines at least one fragmented transmission task based on the transmission draft in step S102 above, which may specifically include the following steps; If the size of the transmitted draft exceeds the preset fragmentation threshold, the front end will divide the transmitted draft into multiple data fragments. Each data fragment includes a fragmentation number, a byte offset, and a fragmentation hash value. If the size of the transmitted draft is less than or equal to the preset fragmentation threshold, the front end will transmit the draft as a data fragment. At least one fragmentation transmission task corresponds to one data fragment.

[0041] In one possible implementation, the preset fragmentation threshold can be set to 100MB. When the size of the transmitted file is larger than the preset fragmentation threshold, it is determined to be a large file and fragmented transmission mode is used; when the size of the transmitted file is smaller than or equal to the preset fragmentation threshold, it is determined to be a small file and whole-file transmission mode is used. The preset fragmentation threshold can be determined according to the actual situation, and there is no specific restriction here.

[0042] In one possible implementation, when using a fragmented transmission mode, the front end can segment the transmission file according to a fixed fragment size, for example, a fixed fragment size of 50MB. After segmentation, each data fragment is assigned a fragment sequence number, byte offset, and fragment hash value, and each data fragment corresponds to a fragmented transmission task. When using a whole-fragment transmission mode, there is no need to perform file segmentation; the complete file to be transmitted is treated as a single data fragment, and a single fragmented transmission task is generated accordingly.

[0043] This embodiment can flexibly divide the transmission draft into multiple data fragments or treat the transmission draft as a single data fragment based on the comparison between the size of the transmission draft and the preset fragmentation threshold. Each fragment transmission task is then associated with a data fragment, thereby determining the fragment transmission task at the granularity of the data fragment. This enables differentiated fragmentation processing for files of different sizes, adapting the corresponding transmission granularity to files of different sizes to be transmitted.

[0044] This application embodiment provides a possible implementation method. Before the main process distributes at least one fragmentation transmission task to at least one worker thread in the thread pool in step S103 above, it may further include the following steps: Create a thread pool based on the number of CPU cores and memory capacity.

[0045] In one possible implementation, the main process can first read the hardware resource parameters of the running device, including the number of CPU cores and total memory capacity, and then adaptively create a worker thread pool based on these parameters. The number of threads in the thread pool is calculated using the following formula:

[0046] WORKER_POOL_SIZE represents the number of threads. The memory limit is determined according to the tiered configuration rules: 2 for less than 4GB of memory, 4 for 4GB ≤ memory and less than 8GB, 6 for 8GB ≤ memory and less than 16GB, and 8 for ≥16GB of memory. The formula decrements the number of CPU cores by 1 to reserve at least one CPU core for the Electron main process, page rendering, and UI (User Interface) interaction, avoiding page lag caused by worker threads occupying all CPU cores. The minimum thread count is set to 2, and the number of concurrent shards is consistent with the number of threads to ensure that the thread pool size matches the device hardware capacity.

[0047] This embodiment can adaptively create a thread pool based on the number of CPU cores and memory capacity, so that the number of worker threads in the thread pool matches the actual computing resources of the device, thereby avoiding resource overload and thread congestion caused by too many threads, or idle device resources caused by too few threads, thereby improving resource utilization and operational stability.

[0048] This application embodiment provides a possible implementation method. Before step S104 above, in which at least one worker thread executes at least one fragment transmission task in parallel to obtain the target file, the following steps may be included: Calculate and output the transmission progress, which indicates the progress of the transmission of the manuscript.

[0049] In one possible implementation, the transmission progress can be calculated in real time during the transmission process, and the transmission progress is calculated according to the following formula:

[0050] The maximum value for the transmission progress is 1.0. During the transmission of a single fragment, the real-time transmission progress can be reported at fixed time intervals of 500 milliseconds. The progress data can be synchronized to the front end through the inter-process communication progress push channel. After the fragment transmission is completed, the completion status of the corresponding fragment can be fed back immediately.

[0051] This embodiment calculates the completion status of the segmented transmission task and the number of bytes transmitted within the segment in real time according to a preset progress calculation formula. During the transmission process, the transmission progress within the segment is reported at preset time intervals, and the status is fed back immediately after the segmented transmission is completed. This enables accurate and real-time display of the transmission progress of the transmission draft, allowing users to know the transmission status in a timely manner and improving the interactive experience.

[0052] This application embodiment provides a possible implementation method. Before step S105 is based on the first fingerprint verification target file, it may further include the following steps: In response to a pause command, mark at least one unfinished fragment transmission task in the fragment transmission task as paused, and retain the data corresponding to at least one fragment transmission task; Alternatively, in response to a cancellation command, terminate the network connection of at least one worker thread and clear the data corresponding to at least one fragmented transfer task.

[0053] This embodiment marks incomplete fragment transmission tasks as paused in response to a pause command while retaining all data corresponding to the fragment transmission tasks. This fully preserves the current transmission context, eliminating the need to retransmit completed fragments upon subsequent resumption, thus avoiding redundant network requests and computational waste. By terminating the network connection of the worker thread and clearing the data corresponding to the fragment transmission tasks in response to a cancel command, thread resources and network connections can be released in a timely manner, preventing residual tasks from continuously occupying system resources. This achieves a flexible control effect of pause-and-resume transmission and cancellation-and-release at the task management level, improving resource utilization and operational adaptability of transmission task management.

[0054] This application embodiment provides a possible implementation method. The above step S105 is based on the first fingerprint verification target file and may specifically include the following steps: Calculate the second fingerprint of the target file; If the second fingerprint matches the first fingerprint, set the status of the transmitted draft to transmission complete; If the second fingerprint is inconsistent with the first fingerprint, set the status of the transmitted draft to transmission error.

[0055] This embodiment can perform integrity verification on the target file based on the first fingerprint. By comparing whether the hash value of the target file is consistent with the first fingerprint, it can accurately identify whether the target file has been lost, damaged or fragmented during transmission, thereby ensuring the integrity and accuracy of file transmission.

[0056] The above introduces Figure 1 The embodiments shown have various implementation methods for each stage. The following will further illustrate an Electron multi-threaded file transfer method based on front-end preprocessing according to specific embodiments.

[0057] See Figure 2 , Figure 2 This specific embodiment provides an overall architecture diagram of an Electron multi-threaded file transfer method based on front-end preprocessing, as shown below. Figure 2 As shown, the overall architecture is divided into five layers: The first layer is the front-end rendering layer, implemented using Vue 2 (Vue Version 2, the second version of the Vue front-end development framework), responsible for file acquisition, preprocessing, interactive operations, and local caching; the second layer is the IPC communication layer, implemented based on Electron IPC, divided into three communication channels: request-response, progress push, and auxiliary operation; the third layer is the main process scheduling layer, implemented based on Electron Main, responsible for draft parsing, thread pool management, task distribution, global control, and data persistence; the fourth layer is the worker thread layer, implemented based on worker_threads (a multi-worker thread module), responsible for chunked upload / download, chunk merging, exception retries, and progress reporting; the fifth layer is the back-end service layer, responsible for SM3 hash calculation, integrity verification, and file storage services. The layers coordinate with each other through IPC channels and network requests to achieve a closed-loop process from file preprocessing to transmission completion.

[0058] This specific embodiment includes the following roles and files: User U1: The file uploader selects a 200MB PDF file, "Project Due Diligence Report.pdf", for local upload.

[0059] File to be transferred F: File name "Project Due Diligence Report.pdf", file extension pdf, file size 200MB.

[0060] Target file F': The complete file obtained after the file transfer is completed.

[0061] Transmission File D: A standardized data file generated during the preprocessing stage, containing the first fingerprint, fragment mapping information, transmission parameters, etc.

[0062] 1. The front end performs preprocessing operations on the file to be transmitted to obtain a transmission draft including the first fingerprint. See Figure 3 , Figure 3 This is a schematic diagram of a front-end preprocessing process provided in this specific embodiment. Figure 3 As shown, after the rendering layer calls the File API (File Application Programming Interface) to obtain the file, it sequentially performs file compliance verification, file fingerprint preprocessing, dynamic fragmentation preprocessing, and transmission parameter preconfiguration. Finally, the complete transmission draft is cached locally, and the process enters the inter-process communication phase. Specifically: 1. User U1 clicks the upload button in the Electron client rendering layer and selects the local file "Project Due Diligence Report.pdf". The rendering layer obtains the file F to be transferred via the File API.

[0063] 2. File Compliance Verification: This function verifies whether the file extension "pdf" is within a preset whitelist. The whitelist includes extensions such as xlt, et, xltx, csv, xltm, ett, mp4, mp3, avi, rmvb, wma, wps, bmp, eml, img, ppt, vsd, jsp, js, html, xml, aspx, xlsx, rtf, docx, gif, doc, pptx, java, bat, jpg, txt, png, pdf, jpeg, xls, and xlsm. The verification confirms that "pdf" is on the whitelist. The function then checks the file size. The preset maximum file size is 300MB, with the front-end using 100MB increments to differentiate between large and small files. File F, with a size of 200MB, is considered a large file as it is within the 300MB limit but larger than 100MB. Finally, the function checks for file corruption. If the file extension is invalid, the file size exceeds the preset limit, or the file is corrupted, the transmission request is blocked, and the transmission process is terminated.

[0064] 3. File fingerprint preprocessing: After the front end completes the basic screening, it uses the SM3 algorithm to calculate a unique hash fingerprint for the complete file F, obtains the first fingerprint H1, and writes it into the transmission copy D as the basis for file integrity verification.

[0065] 4. Dynamic Fragmentation Preprocessing: Dynamic fragmentation is performed with 50MB as the fixed fragmentation baseline. File F is 200MB in size, which is greater than 100MB, so it is determined to be a large file and fragmented for transmission. File F is divided into 4 data fragments, each fragment being 50MB; a fragment sequence number, byte offset, and fragment hash value are generated for each data fragment, a fragmentation mapping draft is constructed, and written to the transmission draft D.

[0066] 5. Pre-configuration of transmission parameters: Pre-write parameters such as the number of concurrent transmissions, timeout threshold, maximum number of retries, server interface address, local storage path, session cookie (a type of browser session credential), file service identifier, and interface format identifier into the transmission file D, and cache the transmission file D to local temporary storage to avoid dynamic parsing lag during transmission.

[0067] 6. After preprocessing, the transmission draft D contains the first fingerprint H1, the fragment mapping information of the four data fragments, and the pre-configured transmission parameters.

[0068] II. The front end determines at least one fragment transmission task based on the transmission draft. 1. The front end determines four fragment transmission tasks based on the fragment mapping information recorded in the transmission draft D. Each fragment transmission task corresponds to a data fragment.

[0069] 2. Each fragment transmission task includes the fragment sequence number, byte offset, and fragment hash value of the data fragment.

[0070] 3. The front end synchronizes the four fragmented transmission tasks to the main process through the Electron IPC channel, and the main process then distributes the subsequent tasks.

[0071] 3. The main process distributes at least one fragmented transfer task to at least one worker thread in the thread pool. See Figure 4 , Figure 4 This is a schematic diagram illustrating a process for distributing fragmented transmission tasks according to a specific embodiment. Figure 4 As shown, the rendering layer synchronizes the transmitted draft to the main process via the IPC channel. After parsing the draft, the main process reads the number of CPU cores and device memory, and adaptively creates a Worker thread pool according to a formula. Then, it uniformly divides the IPC communication channels into three types, controls global concurrency using p-limit (a concurrency limiting library), manages the internal queues of the Worker thread pool, and distributes tasks to each Worker thread based on the total number of fragments, priority, and device load balancing. Specifically: 1. After the main process parses and transmits the original document D, it reads the number of CPU cores and total memory of the device. Assume the device has 8 CPU cores and 16GB of memory. The memory limit rule is: ≥16GB memory requires 8 threads. The calculated thread pool size WORKER_POOL_SIZE is 7. The number of concurrent shards is consistent with the number of threads.

[0072] 2. The main process creates a worker thread pool containing 7 worker threads.

[0073] 3. Unified division of IPC communication: The request and response classes adopt the ipcRenderer.invoke / ipcMain.handle pattern for obtaining cookies, submitting chunk uploads / downloads, canceling tasks, and querying thread pool status; the progress push class adopts the webContents.send / ipcRenderer.on pattern for real-time push of chunk progress and intra-chunk transmission progress; the general auxiliary classes are used for auxiliary operations such as setting cookies, session refresh, logging out, and opening directory selection boxes.

[0074] 4. Two-level rate limiting is implemented using p-limit and a thread pool: p-limit controls the global concurrency, and the thread pool manages the internal task queue. The main process, combined with the total number of file fragments, task priority, and device load, evenly distributes the four fragment transmission tasks to the four idle threads among the seven worker threads.

[0075] IV. At least one worker thread executes at least one fragment transfer task to obtain the target file. See Figure 5 , Figure 5 This is a schematic diagram illustrating the execution of a fragmented transmission task provided in this specific embodiment. Figure 5 As shown, each Worker thread establishes an HTTP session and performs chunked upload or download based on the chunked task type. It supports capabilities such as progress calculation and reporting, incremental backoff and retry for network anomalies, pause / cancellation control, and isolation of abnormal threads. Specifically: 1. Four worker threads establish HTTP transmission sessions and independently execute the chunked upload task.

[0076] 2. Chunked Upload: Each worker thread reads the local chunked file, adapts the multipart / form-data (a type of multipart form data) request format according to the task type, configures the request header, cookie and timeout, and then completes the chunked upload of the file stream.

[0077] 3. Progress Calculation and Reporting: Calculate the global transmission progress according to the formula. During the transmission of a single segment, report the real-time progress every 500 milliseconds. Feedback the status immediately after the segment transmission is completed.

[0078] 4. Network Anomaly Handling and Retry: During fragmented transmission, the network's operational status is monitored. If any of the four network anomalies—connection reset, connection timeout, connection rejection, or request timeout—occur, fragmented transmission is re-executed using the built-in retry logic in the worker thread. The retry logic allows for a maximum of 3 retries with an incremental backoff strategy of 1 second, 2 seconds, and 3 seconds. If all retries fail, the system automatically switches to serial transmission mode.

[0079] 5. Task Pause and Cancellation: During chunked transmission, users can manually cancel or pause transmission tasks. In response to a pause command, the system marks incomplete chunked transmission tasks as paused, retaining local chunk files, transmission records, and task queues for later resumption. In response to a cancellation command, the system clears the p-limit queue and thread pool task queue, terminates worker threads and network connections, and clears all task data. The system uses a collection to record completed chunk numbers, effectively avoiding duplicate transmissions. The main process performs real-time status monitoring of all worker threads, automatically isolating abnormal threads to ensure normal transmission of remaining chunks, and simultaneously pushing exception information to the rendering layer for display.

[0080] 6. After all data fragments have been transmitted, the four data fragments are merged to obtain the target file F', which is the complete file obtained based on the four data fragment transmission tasks.

[0081] V. Verify the target file based on the first fingerprint See Figure 6 , Figure 6 This is a schematic diagram of a file verification process provided for this specific embodiment. Figure 6 As shown, after all fragments have been transmitted, the backend recalculates the SM3 hash of the complete file and compares it with the fingerprint of the transmission draft. If the verification matches, the transmission is marked as complete and the local fragment temporary files are cleaned up; if the verification does not match, the transmission is marked as abnormal and a retransmission is triggered. Specifically: 1. After all fragments are transmitted, the backend recalculates the complete file hash value of the target file F' using the SM3 algorithm to obtain the second fingerprint H2.

[0082] 2. Compare the second fingerprint H2 with the first fingerprint H1 in the transmitted manuscript D to complete the second integrity verification.

[0083] 3. If H2 and H1 are consistent, the verification passes, the status of the transmission draft D is updated to transmission complete, local fragment temporary files are automatically cleaned up, storage space is released, and the overall process ends normally.

[0084] 4. If H2 and H1 are inconsistent, the verification fails, the transmission is marked as abnormal, the retransmission mechanism is triggered, and the process returns to the multi-threaded transmission stage to ensure the accuracy of file transmission.

[0085] This specific embodiment reduces the computational load on the main process and avoids page lag by moving the preprocessing operation to the front end; and achieves differentiated file transmission by executing the fragmented transmission task through a thread pool.

[0086] It should be noted that the sequence numbers of the steps in the above embodiments do not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. In practical applications, all the above possible implementation methods can be arbitrarily combined in a combined manner to form possible embodiments of this application, which will not be described in detail here.

[0087] Based on the above embodiments of the Electron multi-threaded file transfer method based on front-end preprocessing, and based on the same inventive concept, this application also provides an Electron multi-threaded file transfer device based on front-end preprocessing.

[0088] Figure 7 This is a structural diagram of the Electron multi-threaded file transfer device based on front-end preprocessing provided in an embodiment of this application. Figure 7 As shown, the Electron multi-threaded file transfer device based on front-end preprocessing may specifically include a first processing unit 210, a second processing unit 220, a task scheduling unit 230, a task execution unit 240, and a file verification unit 250.

[0089] The first processing unit 210 is used to perform preprocessing operations on the file to be transmitted at the front end to obtain a transmission draft including the first fingerprint; The second processing unit 220 is used for the front end to determine at least one fragmented transmission task based on the transmission draft. The task scheduling unit 230 is used by the main process to distribute at least one fragmented transmission task to at least one worker thread in the thread pool. The task execution unit 240 is used for at least one worker thread to execute at least one fragmented transfer task to obtain a target file, wherein the target file is a complete file obtained based on at least one fragmented transfer task; The file verification unit 250 is used to verify the target file based on the first fingerprint.

[0090] This application embodiment provides a possible implementation, wherein the second processing unit 220 is further configured to: If the size of the transmitted draft exceeds the preset fragmentation threshold, the front end will divide the transmitted draft into multiple data fragments. Each data fragment includes a fragmentation number, a byte offset, and a fragmentation hash value. If the size of the transmitted draft is less than or equal to the preset fragmentation threshold, the front end will transmit the draft as a data fragment. At least one fragmentation transmission task corresponds to one data fragment.

[0091] This application embodiment provides a possible implementation, wherein the task scheduling unit 230 is further configured to: Create a thread pool based on the number of CPU cores and memory capacity.

[0092] This application embodiment provides a possible implementation, wherein the task execution unit 240 is further configured to: Calculate and output the transmission progress, which indicates the progress of the transmission of the manuscript.

[0093] This application embodiment provides a possible implementation, wherein the task execution unit 240 is further configured to: In response to a pause command, mark at least one unfinished fragment transmission task in the fragment transmission task as paused, and retain the data corresponding to at least one fragment transmission task; Alternatively, in response to a cancellation command, terminate the network connection of at least one worker thread and clear the data corresponding to at least one fragmented transfer task.

[0094] This application embodiment provides a possible implementation, wherein the file verification unit 250 is further configured to: Calculate the second fingerprint of the target file; If the second fingerprint matches the first fingerprint, set the status of the transmitted draft to transmission complete; If the second fingerprint is inconsistent with the first fingerprint, set the status of the transmitted draft to transmission error.

[0095] Based on the same inventive concept, this application also provides an electronic device, including a processor and a memory, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute an Electron multi-threaded file transfer method based on front-end preprocessing according to any of the above embodiments.

[0096] In an exemplary embodiment, an electronic device is provided, such as Figure 8 As shown, Figure 8 The illustrated electronic device 300 includes a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, for example, via a bus 302. Optionally, the electronic device 300 may also include a transceiver 304. It should be noted that in practical applications, the transceiver 304 is not limited to one type, and the structure of this electronic device 300 does not constitute a limitation on the embodiments of this application.

[0097] Processor 301 may be a CPU (Central Processing Unit), GPU (Graphics Processing Unit), DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA, or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0098] Bus 302 may include a pathway for transmitting information between the aforementioned components. Bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 302 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0099] The memory 303 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.

[0100] The memory 303 stores computer program code that executes the scheme of this application, and its execution is controlled by the processor 301. The processor 301 executes the computer program code stored in the memory 303 to implement the content shown in the foregoing method embodiments.

[0101] Among them, electronic devices include, but are not limited to: mobile terminals such as mobile phones, laptops, digital radio receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (such as in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 8 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0102] Based on the same inventive concept, this application also provides a storage medium storing a computer program, wherein the computer program is configured to execute, at runtime, an Electron multi-threaded file transfer method based on front-end preprocessing of any of the above embodiments.

[0103] Based on the same inventive concept, this application also provides a computer program product, including a computer program configured to execute, at runtime, an Electron multi-threaded file transfer method based on front-end preprocessing of any of the above embodiments.

[0104] Those skilled in the art will clearly understand that the specific working process of the systems, devices, and modules described above can be referred to the corresponding process in the foregoing method embodiments. For the sake of brevity, it will not be repeated here.

[0105] Those skilled in the art will understand that the technical solution of this application, or all or part of it, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several program instructions to cause an electronic device (e.g., a personal computer, server, or network device) to execute all or part of the steps of the methods described in the embodiments of this application when running the program instructions. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0106] Alternatively, all or part of the steps of the foregoing method embodiments can be implemented by hardware (such as electronic devices like personal computers, servers, or network devices) associated with program instructions. The program instructions can be stored in a computer-readable storage medium. When the program instructions are executed by the processor of the electronic device, the electronic device executes all or part of the steps of the methods described in the embodiments of this application.

[0107] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that within the spirit and principles of this application, modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the corresponding technical solutions to leave the protection scope of this application.

Claims

1. A multi-threaded file transfer method using Electron based on front-end preprocessing, the method comprising: The front end performs preprocessing operations on the file to be transmitted to obtain a transmission draft including the first fingerprint; The front end determines at least one fragment transmission task based on the transmission draft; The main process distributes at least one fragment transfer task to at least one worker thread in the thread pool; At least one worker thread executes at least one fragment transfer task to obtain a target file, which is a complete file obtained based on at least one fragment transfer task; Verify the target file based on the first fingerprint.

2. The method according to claim 1, characterized in that, The front end determines at least one fragment transmission task based on the transmission draft, including: If the size of the transmitted draft exceeds the preset fragmentation threshold, the front end will divide the transmitted draft into multiple data fragments. Each data fragment includes a fragmentation number, a byte offset, and a fragmentation hash value. If the size of the transmitted draft is less than or equal to the preset fragmentation threshold, the front end will transmit the draft as a data fragment. At least one fragmentation transmission task corresponds to one data fragment.

3. The method according to claim 1, characterized in that, Before the main process distributes at least one fragmented transfer task to at least one worker thread in the thread pool, it also includes: Create a thread pool based on the number of CPU cores and memory capacity.

4. The method according to claim 3, characterized in that, At least one worker thread executes at least one fragmented transfer task in parallel to obtain the target file, including: Calculate and output the transmission progress, which indicates the progress of the transmission of the manuscript.

5. The method according to claim 4, characterized in that, Before verifying the target file based on the first fingerprint, the following is also included: In response to a pause command, mark at least one unfinished fragment transmission task in the fragment transmission task as paused, and retain the data corresponding to at least one fragment transmission task; Alternatively, in response to a cancellation command, terminate the network connection of at least one worker thread and clear the data corresponding to at least one fragmented transfer task.

6. The method according to any one of claims 1 to 5, characterized in that, Based on the first fingerprint verification target file, including: Calculate the second fingerprint of the target file; If the second fingerprint matches the first fingerprint, set the status of the transmitted draft to transmission complete; If the second fingerprint is inconsistent with the first fingerprint, set the status of the transmitted draft to transmission error.

7. A multi-threaded file transfer device based on front-end preprocessing in Electron, characterized in that, The device includes: The first processing unit is used to perform preprocessing operations on the file to be transmitted at the front end to obtain a transmission draft including the first fingerprint; The second processing unit is used by the front end to determine at least one fragmented transmission task based on the transmission draft. The task scheduling unit is used by the main process to distribute at least one fragmented transmission task to at least one worker thread in the thread pool. The task execution unit is used by at least one worker thread to execute at least one fragmented transfer task to obtain a target file, which is a complete file obtained based on at least one fragmented transfer task; The file verification unit is used to verify the target file based on the first fingerprint.

8. An electronic device, characterized in that, The method includes a processor and a memory, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the Electron multithreaded file transfer method based on front-end preprocessing as described in any one of claims 1 to 6.

9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the Electron multi-threaded file transfer method based on front-end preprocessing as described in any one of claims 1 to 6 at runtime.

10. A computer program product, comprising a computer program, characterized in that, The computer program is configured to execute the Electron multithreaded file transfer method based on front-end preprocessing as described in any one of claims 1 to 6 at runtime.