File processing method and device in applet, equipment and readable storage medium
Patent Information
- Application Number
- CN202210394105.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-14
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2042-04-14
AI Technical Summary
其中,小程序中支持文件访问操作的API,通常是获取目标文件的文件数据,然后将文件数据在小程序架构中各层之间进行传输,实现文件的访问操作,如此,对于频繁的文件访问操作,小程序各层之间数据通信量大,降低了文件的操作效率,人机交互体验差
[0045]应用本申请实施例,小程序的逻辑层将确定的目标文件的地址、以及目标文件对应的数据缓冲区的地址发送至小程序的系统层,使得系统层可以调用文件管理接口,得到目标文件中的目标数据,并将目标数据存储至数据缓冲区;然后,逻辑层对数据缓冲区中的目标数据执行与文件访问操作所指示的数据处理类型对应的数据操作,即在针对目标文件的文件访问操作过程中,逻辑层和系统层通过操作数据缓冲区中的目标数据实现针对目标文件的访问操作,如此,减少了逻辑层与系统层之间的数据传输次数,降低了数据通信量,提高了小程序中文件的访问效率。
Smart Images

Figure CN116954937B_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and more particularly to a file processing method, apparatus, device, computer-readable storage medium, and computer program product in a small program. Background Technology
[0002] The mini-program development framework provides a rich set of native application programming interfaces (APIs), which can easily invoke the capabilities provided by instant messaging clients, such as retrieving user information, local storage, and payment functions. Among these, the APIs supporting file access operations in mini-programs typically retrieve the file data of the target file and then transfer this data between different layers within the mini-program architecture to achieve file access. This results in a large volume of data communication between the various layers of the mini-program for frequent file access operations, reducing file operation efficiency and leading to a poor human-computer interaction experience. Summary of the Invention
[0003] This application provides a file processing method, apparatus, device, computer-readable storage medium, and computer program product in a mini-program, which can reduce the amount of data communication during file access operations and improve the speed of file access operations.
[0004] The technical solution of this application embodiment is implemented as follows:
[0005] This application provides a file processing method in a mini-program, including:
[0006] When the logic layer of the mini-program receives a file access event for the target file, it determines the address of the target file and the address of the data buffer corresponding to the target file.
[0007] The file access event is generated by the view layer of the mini-program based on the received file access operation for the target file.
[0008] The logic layer sends the address of the target file and the address of the data buffer to the system layer of the mini-program, and the system layer connects the logic layer and the view layer;
[0009] The system layer calls the file management interface based on the address of the target file to obtain the target data in the target file, and stores the target data in the data buffer based on the address of the data buffer;
[0010] The target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
[0011] This application provides a file processing device in a mini-program, including:
[0012] The receiving module is used to determine the address of the target file and the address of the data buffer corresponding to the target file when the logic layer of the mini-program receives a file access event for the target file; wherein, the file access event is generated by the view layer of the mini-program based on the received file access operation for the target file;
[0013] The sending module is used by the logic layer to send the address of the target file and the address of the data buffer to the system layer of the applet, wherein the system layer connects the logic layer and the view layer;
[0014] The storage module is used by the system layer to call the file management interface based on the address of the target file to obtain the target data in the target file, and to store the target data in the data buffer based on the address of the data buffer; the target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
[0015] In the above scheme, the file processing device in the mini-program further includes a detection module, and the creation module is used to obtain the data size of the target data in the target file when the logic layer of the mini-program detects that there is no data buffer corresponding to the target file in memory;
[0016] The logic layer creates a data buffer corresponding to the target file based on the data size of the target data.
[0017] In the above scheme, the detection module is further used to detect the operation permissions of the target object executing the file access operation and the data processing type corresponding to the data processing type based on the data processing type indicated by the file access operation, and obtain the detection result;
[0018] When the detection result indicates that the target object has operation permissions corresponding to the data processing type, the address of the data buffer corresponding to the target file is determined.
[0019] In the above scheme, the storage module is also used for the system layer to obtain the size of the target data and the available capacity of the data buffer;
[0020] When the available capacity of the data buffer is greater than the size of the target data, the system layer stores the target data in the data buffer.
[0021] In the above scheme, the receiving module is also used for the logic layer of the mini-program to parse the file access event and obtain the content operation parameters of the target file. The content operation parameters are used to indicate the position of the target data in the target file. Correspondingly, the storage module is also used for the system layer to call the file management interface based on the address of the target file and the content operation parameters to obtain the target data in the target file.
[0022] The content operation parameters include at least one of the following: the content offset corresponding to the target data and the content length corresponding to the target data.
[0023] In the above scheme, the file management interface includes a file opening interface and a file reading interface. The storage module is also used by the system layer to call the file opening interface based on the address of the target file, open the target file, and control the target file to be in an operable state.
[0024] Based on the content operation parameters, the system layer calls the file reading interface to read the target data from the data of the target file, which is in an operable state.
[0025] In the above scheme, the content operation parameters include the content offset of the target data. The storage module is also used by the system layer to determine the starting position of the content for the target data based on the address of the target file and the content offset.
[0026] The system layer calls the file management interface to read data from the beginning of the target data content until the end of the target data content;
[0027] The data between the start position of the target data content and the end position of the target file content is taken as the target data.
[0028] In the above scheme, the content operation parameters include the content length of the target data, and the storage module is also used by the system layer to determine the starting position of the content of the target file;
[0029] The system layer calls the file management interface to read data of the target length from the beginning of the content of the target file, and uses the data of the target length as the target data;
[0030] The target length is equal to the content length of the target data.
[0031] In the above scheme, the content operation parameters include the content offset of the target data and the content length of the target data. The storage module is also used by the system layer to determine the starting position of the content for the target data based on the address of the target file and the content offset.
[0032] The system layer calls the file management interface to read data of the target length from the beginning position of the target data content in the target file, and uses the data of the target length as the target data.
[0033] The target length is equal to the length of the file content.
[0034] In the above scheme, the storage module is further used to send a notification message from the system layer to the logic layer, the notification message being used to indicate that the storage operation for the target data has been completed;
[0035] The logic layer receives the notification message and performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0036] In the above scheme, the storage module is further configured to, when the data processing type is data update, have the logic layer perform a corresponding data update operation on the target data in the data buffer and send an update instruction to the system layer; accordingly, after receiving the update instruction, the system layer obtains the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
[0037] In the above scheme, the storage module is also used for the logic layer to periodically query the data buffer to obtain query results;
[0038] When the query result indicates that the target data has been stored in the data buffer, the logic layer performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0039] This application provides an electronic device, including:
[0040] Memory, used to store executable instructions;
[0041] The processor, when executing executable instructions stored in the memory, implements the file processing method in the applet provided in the embodiments of this application.
[0042] This application provides a computer-readable storage medium storing executable instructions for inducing a processor to execute and implement the file processing method in the applet provided in this application.
[0043] This application provides a computer program product, including a computer program or instructions, which, when executed by a processor, implements the file processing method in the applet provided in this application.
[0044] The embodiments of this application have the following beneficial effects:
[0045] In the embodiments of this application, the logic layer of the mini-program sends the address of the determined target file and the address of the corresponding data buffer to the system layer of the mini-program. This allows the system layer to call the file management interface to obtain the target data in the target file and store the target data in the data buffer. Then, the logic layer performs data operations on the target data in the data buffer that correspond to the data processing type indicated by the file access operation. That is, during the file access operation for the target file, the logic layer and the system layer perform the access operation for the target file by operating on the target data in the data buffer. This reduces the number of data transmissions between the logic layer and the system layer, reduces the amount of data communication, and improves the file access efficiency in the mini-program. Attached Figure Description
[0046] Figure 1 This is a schematic diagram of the system architecture for running applets on the client side, provided in an embodiment of this application.
[0047] Figure 2 This is a schematic diagram of the structure of the terminal 20 running the client provided in the embodiments of this application;
[0048] Figure 3 This is a schematic diagram of the architecture of the mini-program provided in the embodiments of this application;
[0049] Figure 4 It is a file processing device in the applet provided in the embodiments of this application;
[0050] Figure 5 This is a flowchart illustrating the file processing method in the applet provided in this application embodiment;
[0051] Figure 6 This is a schematic diagram of the file management interface provided in an embodiment of this application;
[0052] Figure 7 This is a schematic diagram illustrating the method for obtaining target data in the target file provided in the embodiments of this application;
[0053] Figure 8 This is a schematic diagram of the method for obtaining target data provided in an embodiment of this application;
[0054] Figure 9 This is another schematic diagram of the method for obtaining target data provided in the embodiments of this application;
[0055] Figure 10 This is a flowchart illustrating the data update method for target data provided in an embodiment of this application;
[0056] Figure 11 This is a flowchart of a file processing method in a mini-program provided in this application embodiment;
[0057] Figure 12 This is a schematic diagram illustrating the call sequence of the file management interface provided in this application embodiment;
[0058] Figure 13 This is a schematic diagram illustrating the actual file reading and writing operation provided in the embodiments of this application. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0060] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0061] If the application documents contain similar descriptions such as "first / second", the following explanation shall be added: In the following description, the terms "first / second / third" are used only to distinguish similar objects and do not represent a specific order of objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0062] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0063] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0064] 1) Client: An application that runs on a terminal and provides various services, such as an instant messaging application.
[0065] 2) Mini Programs are programs developed using front-end-oriented languages (such as JavaScript) and implemented in Hyper Text Markup Language (HTML) pages. They can be interpreted and executed immediately after being downloaded by the client, without requiring an installation step on the client.
[0066] 3) Web-View component, also known as view component, is used to implement various content in a webpage such as clickable elements, drop-down lists, tables, etc. It is responsible for the display of the mini-program and can automatically fill the mini-program's page.
[0067] 4) Events: The communication method from the view layer to the logic layer of the mini-program. When a user operation occurs in the web page view component, the data generated is passed to the logic layer in the form of an event. The event handling function bound to the event is executed in the logic layer, such as calling various system capability interfaces.
[0068] Based on the above explanation of the nouns and terms used in the embodiments of this application, see below. Figure 1 , Figure 1 This is a schematic diagram of the system architecture for running a mini-program on a client provided in this application embodiment. When the client 11 (such as an instant messaging client) set on the terminal 20 runs the mini-program for the first time, it needs to download the mini-program and send an initialization request to the mini-program's server. In order to improve the download speed, the request is redirected to the content delivery network 13 (CDN) to obtain the mini-program's data package, i.e., the source code of the mini-program, from the node server closest to the user, thus realizing the download of the mini-program. After the client initializes the mini-program, it loads the mini-program page. The mini-program sends a data request (Ajax request) to the server 12 to obtain the data required for page display and page updates. Here, AJAX stands for "Asynchronous JavaScript And XML". The web server returns the corresponding JSON (JavaScript Object Notation) formatted page data based on the Ajax request sent by the mini-program. Then, the mini-program renders the page according to the obtained JSON data, realizing the page update of the mini-program on the client.
[0069] Among them, the source code of the mini program obtained by client 11 when downloading the mini program includes the following different types of files: 1) Configuration files with the .json suffix, which are used for the mini program's (global) public settings, determining the path of page files, window appearance, setting network timeout, setting multiple tabs, etc.; 2) Configuration files with the .js suffix, which are used to implement the mini program's (global) logic; 3) Configuration files with the .wxss suffix, which are used for the mini program's public style configuration.
[0070] The structure of terminal 20 running client 11 will be described next. Figure 2 This is a schematic diagram of the structure of the terminal 20 running the client provided in this application embodiment. See also... Figure 2 The terminal includes: a hardware layer 21, a driver layer 22, an operating system layer 23, and an application layer 24. However, those skilled in the art should understand that... Figure 2 The structure of terminal 20 shown is merely an example and does not constitute a limitation on the terminal structure. For example, the terminal can be configured according to implementation needs. Figure 2 More components, or omit some components as needed for implementation.
[0071] Hardware layer 21 includes processor 211, memory 212, input / output interface 213, and communication interface 214. Components can be connected and communicate via a system bus. The processor 211 can be implemented using a central processing unit (CPU), microprocessor (MCU), application-specific integrated circuit (ASIC), or field-programmable gate array (FPGA).
[0072] The input / output interface 213 can be implemented using input / output devices such as a display screen, touch screen, or speaker.
[0073] The memory 212 stores a storage medium, which can be implemented using non-volatile storage media such as flash memory, hard disk, or optical disk, or volatile storage media such as double data rate (DDR) dynamic cache. The storage medium contains an executable program for executing the web page processing methods in the aforementioned applet. Exemplarily, the storage medium can be located in the same place as other components of the terminal, or it can be distributed relative to other components in the terminal. The storage medium includes at least an operating system and a network communication program.
[0074] Communication interface 214 provides the processor with access to external data, such as remotely located storage media.
[0075] The driver layer 22 includes middleware 221 for the operating system to identify the hardware layer and communicate with the components of the hardware layer, such as a collection of drivers for the components of the hardware layer.
[0076] Operating system layer 23 is used to provide a user-facing graphical interface, exemplarily including driver 231, graphics library 232, system framework 233, user interface suite 234, plug-in icon, desktop background and application icon. The operating system layer supports user control of the device through the graphical interface. This application embodiment does not limit the software of the above-mentioned device, such as the type and version of the operating system, for example, it may be a Linux operating system, a UNIX operating system or other operating systems.
[0077] The application layer 24 includes applets 241 and clients 242. Of course, it may also include applications for implementing other conventional functions, such as browsers.
[0078] The architecture of the mini-program 241 in this embodiment will be described next. Figure 3 This is a schematic diagram of the architecture of the mini-program provided in the embodiments of this application, such as... Figure 3 As shown, the core of the mini-program framework is a responsive data binding system. The entire system is divided into two parts: the view layer and the logic layer (APP Service). Through the mini-program framework, corresponding parameters, such as parameter names, can be bound between the view and logic layers, making it very easy to keep data and the view synchronized. When data is modified, only the data needs to be modified in the logic layer, and the view layer will update accordingly. Figure 3 It is known that the view layer and the logic layer run in separate threads, and their information exchange is conducted through the system layer's JSBridge. When a user interacts with a page in the mini-program (e.g., clicks), the view layer's components capture the user's action and trigger events bound to those components (e.g., click events corresponding to clicks). These events are then sent to the logic layer via JSBridge. The logic layer parses the events, executes the corresponding logic (e.g., calls mini-program APIs), and passes the data needed for page updates to the view layer via JSBridge. The view layer then generates a view based on the received data.
[0079] The view layer and logic layer of Mini Program 241 will be explained separately below.
[0080] The primary function of the view layer is to reflect data from the logic layer into a view, and simultaneously send events from the view layer to the logic layer. Components are the basic building blocks of the view layer, possessing built-in functionality and styles. A component typically includes a "start tag" and an "end tag," with "attributes" used to decorate the component, and "content" enclosed within these two tags. Common component attributes include: id (used to uniquely identify the component), class (the component's style class), style (the component's inline style), hidden (whether the component is visible), data-* (custom attributes that can decorate the component's functionality or style), and bind* / catch* (the component's events). Basic components are categorized into eight types: View Container, Basic Content (such as icons, text, progress bars), Forms (such as buttons, input boxes, labels, etc.), Navigation, Multimedia (such as audio, images, video), Map, Canvas, and Customer Service Sessions.
[0081] The logic layer processes the data and sends it to the view layer, while also receiving event feedback from the view layer. Written in JavaScript, it adds `APP` and `Page` methods to register the program and pages. It provides a rich set of APIs, such as media APIs for playing music and previewing images, network APIs for uploading and downloading files, file APIs for saving and opening files, data APIs for retrieving and clearing local data cache, location APIs for getting the current location and opening the built-in map, device APIs for retrieving system information and making phone calls, and UI APIs for displaying prompts and menus, as well as features like scanning and payment. Each page has an independent scope (variables and functions declared in a JavaScript file are only valid within that file; variables and functions with the same name can be declared in different files without affecting each other), and it provides modularity (extracting common code into a separate JS file as a module).
[0082] Events are a communication method between the view layer and the logic layer of a mini-program. They can feed back user page operations to the logic layer for processing. They can be bound to components in the view layer. When an event is triggered, it is passed to the logic layer, and the corresponding event handler function in the logic layer is executed. The event object (which the logic layer receives when the event handler function is bound to the event) can carry additional information, such as ID, dataset, touches, etc.
[0083] So far, the terminal, client, and applet for implementing the embodiments of this application have been described. Continuing with the description of the file processing device in the applet for implementing the embodiments of this application, the file processing device for implementing the applet for implementing the embodiments of this application can be implemented in a combination of hardware and software, for example, by… Figure 2 The processor 211 in terminal 20 can be directly represented as a hardware decoding processor, or it can be executed by a combination of hardware and software modules in the decoding processor.
[0084] Of course, the file processing device in a mini-program can be implemented in software. As an example of software implementation of the file processing device in a mini-program, file processing in a mini-program can be implemented as follows: Figure 2 The client 242 running in terminal 20 shown in the figure, see also Figure 4 , Figure 4 This is a file processing device in the applet provided in this application embodiment. The client 242 includes:
[0085] The receiving module 41 is used to determine the address of the target file and the address of the data buffer corresponding to the target file when the logic layer of the mini-program receives a file access event for the target file; wherein the file access event is generated by the view layer of the mini-program based on the received file access operation for the target file;
[0086] The sending module 42 is used by the logic layer to send the address of the target file and the address of the data buffer to the system layer of the applet, wherein the system layer connects the logic layer and the view layer;
[0087] Storage module 43 is used by the system layer to call the file management interface based on the address of the target file to obtain the target data in the target file, and to store the target data in the data buffer based on the address of the data buffer; the target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
[0088] The file processing method in the applet provided in this application will be described by referring to the exemplary application and implementation of the terminal provided in the embodiments of this application. See also Figure 5 , Figure 5 This is a flowchart illustrating the file processing method in the applet provided in this application embodiment, which will be combined with... Figure 5 The steps shown are explained.
[0089] In step 101, when the logic layer of the mini-program receives a file access event for the target file, it determines the address of the target file and the address of the data buffer corresponding to the target file.
[0090] Among these, the file access event is generated by the mini-program's view layer based on the received file access operation for the target file. Additionally, the address of the data buffer is the starting address of the data buffer in memory space.
[0091] In practice, when a user performs file access operations (such as reading, modifying, or deleting files) on a target file within a mini-program's page via a client, the view layer component captures the user's action and triggers a file access event bound to that component (such as an open event for a file open operation). This file access event is then sent to the mini-program's logic layer via JSBridge. The logic layer parses the file access event to obtain the access parameters for the target file, which include at least the target file's address, i.e., its file path. Upon receiving the file access event for the target file, the mini-program's logic layer can determine the corresponding data buffer for the target file and its starting address in memory. It's important to note that the target file's file path is a path accessible to the mini-program. In practical applications, to reduce data communication between the mini-program's logic layer and the system layer and improve file access efficiency, the mini-program's logic layer can allocate a corresponding data buffer for the target file. This allows the logic layer to retrieve access data for the target file from the data buffer or write modified file data to the data buffer. The system layer of the mini-program can also temporarily store the data read from the target file in the data buffer, and retrieve the updated data of the target file from the data buffer and rewrite it to the target file.
[0092] For example, an instant messaging client is installed on a mobile terminal. The user presents the page of the mini-program A corresponding to the office software through the instant messaging client. The user opens the target file F in the mini-program A and generates a file access request for the target file F. The view layer of the mini-program A determines the corresponding file access operation based on the file access request, generates the corresponding file access event, and then sends the file path (address) of the target file F to the logic layer of the mini-program.
[0093] The data buffer is a buffer (memory space) used to store binary data. It can be a contiguous block of memory in the terminal memory or a non-contiguous block. For example, a binary data buffer like ArrayBuffer converts character data from a target file into binary format.
[0094] In some embodiments, before determining the address of the data buffer corresponding to the target file, the logic layer of the mini-program may create the data buffer in the following way: when the logic layer of the mini-program detects that there is no data buffer corresponding to the target file in memory, it obtains the data size of the target data in the target file; the logic layer creates the data buffer corresponding to the target file based on the data size of the target data.
[0095] In practice, before determining the address of the data buffer corresponding to the target file, the logic layer of the mini-program usually checks whether the data buffer for the target file exists. When the logic layer detects that the data buffer for the target file does not exist in memory, it can create the corresponding data buffer. When creating the data buffer, the logic layer can pre-set the size of the data buffer, which can be determined based on the size of the target data.
[0096] In other embodiments, when the mini-program's logic layer detects the existence of a data buffer corresponding to the target file in memory and the remaining capacity of the data buffer is lower than a remaining capacity threshold, it releases the memory space corresponding to the data buffer. In practical applications, when the mini-program's logic layer detects that a data buffer corresponding to the target file already exists in memory, it also needs to check the remaining capacity of the current data buffer. When the remaining capacity is lower than a preset remaining capacity threshold, it indicates that the data buffer corresponding to the target file is full. At this time, the mini-program's logic layer can release the memory space corresponding to the data buffer or directly allocate a new data buffer to store the relevant data corresponding to the target file.
[0097] In some embodiments, the logic layer of the mini-program can determine the address of the data buffer corresponding to the target file in the following way: the logic layer detects the operation permissions of the target object executing the file access operation corresponding to the data processing type based on the data processing type indicated by the file access operation, and obtains the detection result; when the detection result indicates that the target object has operation permissions corresponding to the data processing type for the target file, the address of the data buffer corresponding to the target file is determined.
[0098] In practice, file access operations on a target file include at least one of read and write operations. Correspondingly, the data processing type for the file access operation can be viewing, editing, or deleting data within the target file. Before accessing the target file, the mini-program's logic layer can first check the access permissions of the target object (user) performing the file access operation. If the target object has the corresponding data processing permissions, the mini-program's logic layer determines the address of the data buffer corresponding to the target file. If the target object does not have the corresponding data processing permissions, a failure message for the access operation can be generated and sent to the mini-program's view layer. The view layer then visualizes the failure message to indicate that the target object performing the file access operation does not have the necessary permissions to access the target file.
[0099] For example, a target object U accesses a mini-program A through an instant messaging client to perform a write operation on a target file (the file access operation is a write operation). The data processing type corresponding to the write operation is an edit operation. At this time, the logic layer of the mini-program checks whether the target object U has the necessary edit permissions for the target file. If the logic layer detects that the target object U has the corresponding permissions, it can continue to perform subsequent operations. If the logic layer detects that the target object U does not have the corresponding permissions, it generates a prompt message "Sorry! Your target does not have edit permissions for file F" and sends this prompt message to the view layer of the mini-program so that the view layer can visualize the prompt message.
[0100] In step 102, the logic layer of the mini-program sends the address of the target file and the address of the data buffer to the system layer of the mini-program.
[0101] The system layer connects the logic layer and the view layer.
[0102] In practice, the mini-program's logic layer sends the address of the target file and the address of the data buffer to the mini-program's system layer. The mini-program's logic layer constructs the corresponding code function for the file access operation and sends the address of the target file and the address of the data buffer as parameters to the function to the mini-program's system layer.
[0103] In this way, the logic layer of the mini-program can send the address of the target file and the address of the data buffer to the system layer of the mini-program.
[0104] In step 103, the system layer of the mini-program calls the file management interface based on the address of the target file to obtain the target data in the target file.
[0105] The target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
[0106] In practice, the system layer of the mini-program, based on the address of the received target file, calls the corresponding file management interface to obtain the target data from the target file. See also... Figure 6 , Figure 6 This is a schematic diagram of the file management interface provided in the embodiment of this application. The file management interface shown in the figure includes an open interface, a read interface, a write interface, and a close interface. The logic layer calls the basic library methods for file operations provided by the platform to which the applet belongs, corresponding to these file management interfaces. open corresponds to inner open, read corresponds to inner read, write corresponds to inner write, and close corresponds to inner close.
[0107] For example, taking opening a file, reading its contents, and modifying and writing those contents back to the file as an example, this illustrates how the system layer of a mini-program obtains the target data from the target file. The code snippet implementing the relevant operations is as follows:
[0108]
[0109] In some embodiments, the system layer of the mini-program can determine the target data in the target file in the following way: the mini-program system layer calls the file management interface based on the address and content operation parameters of the target file to obtain the target data in the target file; wherein, the content operation parameters include at least one of the content offset corresponding to the target data and the content length corresponding to the target data.
[0110] In practice, the system layer of the mini-program can determine the target data in the target file based on the address of the received target file and the corresponding content operation parameters. In other words, the system layer can obtain a portion of the data in the target file as the target data based on the content operation parameters, without needing to read from the beginning of the target file every time. These content operation parameters can include at least one of the content offset and the content length of the target data. Specifically, the system layer can determine the starting position of the target data in the target file (i.e., where to start reading data) based on the content offset, and determine the size of the target data based on the content length. Thus, by combining the content offset and the content length of the target file, the target data is obtained from the target file.
[0111] In some embodiments, the logic layer of the mini-program can obtain the above content operation parameters in the following way: the logic layer of the mini-program parses the file access event to obtain the content operation parameters of the target file, wherein the content operation parameters are used to indicate the position of the target data in the target file.
[0112] In practice, the mini-program's logic layer parses file access events to determine the corresponding content operation parameters. In other words, the target object for the file access operation based on these content operation parameters is transmitted from the mini-program's view layer to its logic layer. Based on this, the logic layer parses the file access event to obtain the content operation parameters. It's important to note that if the content operation parameters set by the target object are not obtained when parsing the access event, the mini-program's logic layer can perform subsequent operations based on default values. If the content operation parameters are empty, the logic layer can set the content offset for the target file to 0 (i.e., start reading the target data from the first character position of the target file); the logic layer can also set the content length corresponding to the target data to the size of the target file (i.e., treat all data in the target file as the target data).
[0113] For example, const fs = wx.getFileSystemManager().readSync({fd,arrayBuffer,offset,length,position}), where arrayBuffer represents the data buffer, offset represents the content offset, and length represents the content length.
[0114] In some embodiments, the file management interface includes a file opening interface and a file reading interface. The system layer of the mini-program can also obtain the target data in the target file in the following ways: the system layer of the mini-program calls the file opening interface based on the address of the target file, opens the target file, and controls the target file to be in an operable state; the system layer of the mini-program calls the file reading interface based on the content operation parameters, and reads the target data from the data of the target file in the operable state.
[0115] In actual implementation, the file management interface can include a file open interface and a file read interface. The system layer of the mini program calls the file open interface to open the target file indicated by the address of the target file. At this time, the target file is controlled to be in an operable state. After detecting and determining that the target object performing the file access operation has the corresponding operation permissions, the file read interface is called based on the content operation parameters to read the data of the target file and obtain the final target data.
[0116] In some embodiments, see Figure 7 , Figure 7 This is a schematic diagram illustrating a method for obtaining target data in a target file provided in an embodiment of this application. When the content operation parameter includes the content offset of the target data, the system layer of the mini-program can... Figure 7 Steps 1031a-1033a shown obtain the target data in the target file.
[0117] Step 1031a: The system layer of the mini-program determines the starting position of the content for the target data based on the address and content offset of the target file.
[0118] In actual implementation, the system layer of the mini-program determines the storage location of the file to be accessed based on the address of the target file, and then determines the starting position of the target data to be read in the target file based on the content offset (content operation parameter), and starts reading data from that starting position until the end position of the target file.
[0119] Step 1032a: The system layer of the mini-program calls the file management interface to read data from the beginning of the target data content until the end of the target data content.
[0120] In practice, when the memory operation parameter is the content offset corresponding to the target file, the system layer determines the starting position of the target data in the target file based on the content offset, and reads the data from that starting position until the end position of the target file's content. That is, the system layer starts reading the target file from the beginning position and continues reading until the end position of the target file's content.
[0121] Step 1033a: Use the data between the start position and the end position of the content of the target file as the target data.
[0122] In actual implementation, the system layer uses the data between the start and end positions of the content in the target file as the final target data to be accessed.
[0123] In some embodiments, participate Figure 8 , Figure 8 This is a schematic diagram of a method for obtaining target data provided in an embodiment of this application. When the content operation parameter includes the content length of the target data, it is based on... Figure 5 Step 103 can be achieved through steps 1031b-1032b.
[0124] Step 1031b: The system layer of the mini-program determines the starting position of the target file's content.
[0125] In practice, when the content operation parameter is the length of the target data, the system layer of the mini-program can directly use the position of the first character in the target file as the target starting position (i.e., read the target file from the beginning).
[0126] Step 1032b: The system layer of the mini-program calls the file management interface to read the target length of data from the beginning of the target file's content as the target data.
[0127] The target length is equal to the content length of the target data.
[0128] In practice, the system layer reads data from the beginning of the target file, and the final size of the read data matches the content operation parameters (i.e., the length of the target data). In other words, the system layer can determine the end position of the target file content based on the content operation parameters (i.e., the length of the target data).
[0129] In some embodiments, participate Figure 9 , Figure 9 This is another schematic diagram of the target data acquisition method provided in the embodiments of this application. When the content operation parameters include the content offset of the target data and the content length of the target data, based on Figure 5 Step 103 can be achieved through steps 1031c-1032c.
[0130] Step 1031c: The system layer of the mini-program determines the starting position of the content for the target data based on the address and content offset of the target file.
[0131] In actual implementation, when the content operation parameters include the content offset and content length of the target data, the system layer can open the target file based on the address of the target file and control the target file to be in an operable state. Then, based on the content offset, the starting position of the target data content in the target file can be determined.
[0132] Step 1032c: The system layer of the mini-program calls the file management interface to read the target length of data from the starting position of the target data content as the target data.
[0133] The target length is equal to the content length of the target data.
[0134] In practice, after determining the starting position of the target data content, the system layer calls the file management interface to read data of the target length starting from the content's beginning position. It should be noted that the system layer determines the ending position of the target data content in the target file based on the content length included in the content operation parameters. In other words, the system layer reads the data between the beginning and end positions of the target data content as the target data.
[0135] In step 104, the system layer of the mini-program stores the target data into the data buffer based on the address of the data buffer.
[0136] In actual implementation, after the system layer reads the target data from the target file, it stores the target data in the data buffer according to the address of the data buffer corresponding to the target file.
[0137] In some embodiments, see Figure 10 , Figure 10 This is a flowchart illustrating the data update method for target data provided in the embodiments of this application, based on... Figure 3 After step 104, the following can also be executed:
[0138] In step 105, the system layer of the mini-program sends a notification message to the logic layer, which indicates that the storage operation for the target data has been completed.
[0139] In practice, when the system layer of the mini-program completes the operation of writing target data to the data buffer, the system layer can send a notification message to the logic layer. This notification message indicates that the system layer has completed the storage operation for the target data. At this time, the logic layer of the mini-program can call the target data in the data buffer.
[0140] In step 106, the logic layer of the mini-program receives the notification message and performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0141] In actual implementation, after the logic layer of the mini-program receives the notification message from the system layer indicating that the writing of the target data to the data buffer is complete, it retrieves the target data from the data buffer according to the data processing type indicated by the file access operation and performs the corresponding data operation on the target data.
[0142] For example, taking the editing operation of target file F as an example, after the system layer writes the target data D in target file F into data buffer B, it sends a notification message to the logic layer. This can be represented by a global variable to indicate the completion of the write operation, such as setting the variable isFinish = false. When the write operation for the target data in the data buffer is completed, the variable isFinish = true. At this time, when the logic layer detects that isFinish has changed from false to true, it determines that the target data to be edited has been stored in the data buffer. Then, the logic layer reads the target data from the data buffer and performs editing operations on the target data (such as adding, modifying, or deleting).
[0143] In some embodiments, when the data processing type indicated by the file access operation for the target file is data update, the logic layer of the mini-program can also update the target data in the following ways: the logic layer of the mini-program performs the corresponding data update operation on the target data in the data buffer and sends an update instruction to the system layer; after receiving the update instruction, the system layer of the mini-program obtains the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
[0144] In some embodiments, the logic layer of the mini-program can also determine that the target data in the data buffer has been stored in the following way: the logic layer of the mini-program performs periodic data queries on the data buffer to obtain query results; when the query results indicate that the target data has been stored in the data buffer, the logic layer performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0145] In practice, the logic layer of the mini-program can periodically query the data buffer. When the query result indicates that the target data has been stored in the data buffer, the logic layer can perform corresponding data operations on the target data according to the data processing type indicated by the file access operation.
[0146] For example, the polling period is set to 3 milliseconds (ms), meaning that the logic layer queries the data buffer every 3ms to determine whether the target data has been completely written to the data buffer. Once it is determined that the target data has been completely written to the data buffer, the corresponding data operations (modification, addition, deletion, etc.) are performed on the target data.
[0147] In some embodiments, when the data processing type indicated by the file access operation for the target file is data update, the logic layer of the mini-program can also update the target data in the following ways: the logic layer of the mini-program performs the corresponding data update operation on the target data in the data buffer and sends an update instruction to the system layer; after receiving the update instruction, the system layer of the mini-program obtains the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
[0148] In actual implementation, when performing data updates on the target file, the logic layer of the mini-program reads the target data from the data buffer and updates the target data (such as appending, modifying, or deleting data). After the data update is completed, an update command is sent to the system layer. After receiving the update command (which determines that the target data in the current data buffer is the updated target data), the system layer performs a data update operation on the target file based on the updated target data in the data buffer (i.e., completes the update of the target file).
[0149] In practice, for a target object to perform a file access operation on a target file, the target file needs to be downloaded to the local storage of the electronic device held by the target object beforehand. Therefore, there are no multiple target objects performing file access operations on the target file. Since the operation is performed locally, various file access operations on the target file are executed sequentially. Therefore, during the operation of the mini-program, for file access operations on the same target file, a file open operation can be called once, and a file close operation can be performed once when the mini-program ends (i.e., the mini-program closes). In other words, within one cycle of the mini-program, only one file open interface and one file close interface need to be called, eliminating the need to open and close the target file for each file access operation. Thus, when there are many file access operations on a target file, only one opening of the target file is needed to perform multiple read or write operations, and after the operation is completed, the target file can be closed once. This reduces a large number of repetitive operations and improves the speed of file operations.
[0150] By applying the embodiments of this application, file access operations on target files implemented through the logic layer, system layer, and view layer of the mini-program are transformed into data operations on the target data in the data buffer, performing data processing types corresponding to the data processing types indicated by the file access operations. That is, the logic layer and system layer of the mini-program directly operate on the target data stored in the data cache, eliminating the need for target data to be transferred between the logic layer and the system layer. Communication between the logic layer and the system layer can be achieved through command sending. This significantly reduces the amount of communication involved in file access within the mini-program, improving file operation efficiency. Furthermore, if there are many file access operations on the target file during a single mini-program run, only one open and one close operation can be performed. This greatly reduces repetitive operations and improves file operation speed.
[0151] In some embodiments, see Figure 11 , Figure 11 This is a flowchart of a file processing method in a mini-program provided in this application embodiment, which can be implemented collaboratively by the client to which the mini-program belongs and the server of the mini-program.
[0152] Step 201: The client sends a request from the mini-program to the client's backend server.
[0153] In practice, the user sends a launch request to the mini-program from the client. The client receives the launch request for the mini-program and forwards it to the client's backend server.
[0154] Step 202: The client receives the returned source code of the mini-program.
[0155] In practice, the client obtains the mini-program by sending a request. The client (such as an instant client) can actively obtain the mini-program or based on the user's search in the client. For example, if the user enters the mini-program's function entry point in the client, the user is prompted to install the mini-program, or the mini-program is downloaded based on the user's keyword search. The entry point of the mini-program is displayed in the client, and when an operation that triggers the entry point is received, the request for the mini-program is sent.
[0156] It should be noted that the mini program only needs to be downloaded when the client runs it for the first time, i.e., to obtain the source code of the mini program. After that, it can be used directly.
[0157] Step 203: The client creates a network view component for the mini-program and displays the webpage of the business domain name carried by the network view component in the page frame of the mini-program.
[0158] Step 204: The client receives file data sent based on the file access operation for the target file.
[0159] When a user opens a webpage through a mini-program, the user can manipulate files within the mini-program through the webpage, generating corresponding data.
[0160] Step 205: The client encapsulates the data into an event and sends the event to the view layer of the mini-program.
[0161] In practice, the data includes the mini-program interfaces and parameters required for file management operations. After receiving the data from the webpage, the client sends the data to the mini-program's logic layer as an event, thus notifying the mini-program.
[0162] Step 206: The view layer of the mini-program sends an access event for the target file to the logic layer of the mini-program. The logic layer determines the address of the target file and the address of the data buffer corresponding to the target file.
[0163] Step 207: The logic layer of the mini-program sends the address of the target file and the address of the data buffer corresponding to the target file to the system layer of the mini-program.
[0164] Step 208: The system layer of the mini-program calls the file management interface based on the address of the target file to obtain the target data in the target file.
[0165] Step 209: The system layer of the mini-program stores the target data into the data buffer based on the address of the data buffer.
[0166] Step 210: The system layer of the mini-program sends a notification message indicating that the data buffer has been written to the logic layer of the mini-program.
[0167] Step 211: The logic layer of the mini-program performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0168] Step 212: The client confirms that the target file operation was successful and displays a notification.
[0169] In practice, when a file access operation on a target file is completed, the client can generate a corresponding prompt message to indicate to the user that the file access was successful. For example, during an update operation, the client can indicate to the user that the file update was successful.
[0170] By applying the embodiments of this application, the logic layer and system layer of the mini-program directly operate on the target data stored in the data cache, eliminating the need for data transfer between the logic layer and system layer. Communication between the logic layer and system layer can be achieved through command transmission, thus significantly reducing the amount of communication required for file access within the mini-program and improving file operation efficiency. Furthermore, if there are numerous file access operations on the target file during a single mini-program run, only one open and one close operation can be performed. This greatly reduces repetitive operations and improves file operation speed.
[0171] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.
[0172] The file system is a storage system and corresponding management interface provided by a mini-program or mini-game, isolated from the user. However, in related technologies, the file management interface provided by the mini-program's file system requires the complete opening and closing of the file each time it is read or written, and the entire file content needs to be accessed each time it is written. Furthermore, the data in the file needs to undergo data conversion and communication from the system layer (Native) to the logic layer (the logic layer implemented using JS).
[0173] Based on this, this application provides a file processing method in a mini-program that supports high-performance, atomic operations on files in the mini-program or mini-game. Specifically, it supports performing a single file open operation in the mini-program or mini-game, allowing multiple read or write operations on the file, and finally performing a single file close operation (i.e., supporting finer-grained file read or write operations, etc.). File data can be directly stored in binary form in the data buffer ArrayBuffer defined in the logic layer, without the need for file data transmission between the system layer native and the logic layer JS, effectively reducing the amount of data communication between the layers of the mini-program.
[0174] Before explaining the file processing procedure within the mini-program, let's first describe the mini-program's architecture. See [link to mini-program documentation]. Figure 3During the development of a mini-program, the application programming interfaces (APIs) related to file processing are provided by the mini-program's logic layer, which can communicate with the system layer (native). When reading a file, the original file interface requires data conversion communication from the system layer (native) to the logic layer (JS), which incurs some communication time. To reduce this time, this embodiment sets up a data buffer (ArrayBuffer). When the logic layer calls the API, it directly passes an ArrayBuffer instance. Then, the system layer (native) directly writes the file data of the target file into the data buffer (ArrayBuffer). After the data buffer completes its write operation on the target file, the logic layer can directly read the data from the data buffer (ArrayBuffer) and return.
[0175] In actual implementation, please refer to Table 1, which is a comparison diagram of the file management interfaces provided in the embodiments of this application.
[0176]
[0177] Table 1
[0178] By comparing the file management interfaces shown in Table 1, it can be seen that the file operation capabilities of the two file management interfaces remain unchanged. However, the underlying code implementation of the file management interface provided in this application embodiment has changed. It is precisely because of this change that the FD (File Descriptor) interface (the file management interface provided in this application embodiment) can achieve higher performance and more atomicity than the original interface.
[0179] For example, let's take opening a file, reading its contents, and modifying the contents to write them back to the file as an example to illustrate file handling methods in a mini-program:
[0180] a) The file management interface provided by the relevant documents is implemented in the following code for the above example:
[0181] const fs = wx.getFileSystemManager(); / / Get the globally unique file manager
[0182] data = fs.readFileSync(“FileA”); / / Read file
[0183] data = modify(data); / / Modify file content
[0184] fs.writeFileSync(“FileA”, data); / / Write to file
[0185] b) The implementation code of the file management interface provided in this application embodiment for the above example is as follows:
[0186] const fs = wx.getFileSystemManager() / / Get the globally unique file manager
[0187] fd = fs.openSync("FileA") / / Open the file
[0188] fs.readSync({fd, arrayBuffer, offset, length, position}) / / Reads a file
[0189] data = modify(data) / / Modify file content
[0190] fs.writeSync({fd,data,offset,length,position}) / / Write to file
[0191] fs.closeSync({fd:fd}) / / Close the file
[0192] Through the two implementation methods a) and b) described above, it can be seen that the file management interface provided in this application embodiment has two more operations than the original file management interface: one is to open the file (openSync), and the other is to close the file (closeSync). However, since the original file management interface requires completely opening and closing the file content for each read or write operation, and requires inputting or outputting the entire file content each time it reads or writes a file.
[0193] From a technical perspective, the file management interface provided in this application improves the speed of file operations. To enhance file operation speed, the APIs of mini-programs or mini-games provide a file FD interface to improve file system operation speed, specifically in the following aspects:
[0194] 1) Provide an interface for opening or closing files.
[0195] In actual implementation, see Figure 12 , Figure 12 This is a schematic diagram illustrating the call sequence of the file management interface provided in this application embodiment. Figure 12 (1) In the use of the original interface shown, each file read or write operation requires fully opening and closing the file. If there are many file operations, each file read or write operation requires fully opening and closing the file. This process can be time-consuming and repetitive. Based on this, this application provides two interfaces: openSync for opening a file and closeSync for closing a file. See [link to relevant documentation]. Figure 12 (2) During file operations, opening and closing the file is entirely at the developer's discretion. When there are many file operations, the file only needs to be opened once to perform multiple read or write operations, and then the file can be closed after the operation is completed. Compared with the original interface, this reduces a lot of repetitive operations and improves the speed of file operations.
[0196] 2) Atomic operations are supported for reading or writing files.
[0197] In actual implementation, see Figure 13 , Figure 13 This is a schematic diagram illustrating the actual file read / write operation provided in this embodiment. For the original file management interface, each read or write operation requires manipulating the entire file content. However, in actual development, many developers modify file content rather than rewriting it entirely. In this case, enabling developers to perform atomic file operations can significantly reduce unnecessary read / write operations.
[0198] 3) File data is written directly to the data buffer ArrayBuffer.
[0199] In actual implementation, see Figure 3 The illustrated mini-program architecture, based on which the original file reading interface required data conversion and communication between the native and JS threads, which was time-consuming, allows developers to directly pass an ArrayBuffer instance when calling the new FD read interface. The native system layer then directly stores the read file data into the ArrayBuffer, and the JS logic layer can then directly read the file data from the ArrayBuffer and return it.
[0200] In summary, the file processing process in the mini-program or mini-game provided in this application embodiment is as follows: When a developer reads a file, a data buffer ArrayBuffer is created and used as a parameter of the interface wx.getFileSystemManager.readSync. After the system layer Native receives this file read instruction, it stores the read target file data into the data buffer ArrayBuffer. After the target file data is written, it sends a notification message indicating that the writing is complete to the logic layer. At this time, the logic layer can directly access the data buffer ArrayBuffer after determining that the target file data has been written, and obtain the target file data from the ArrayBuffer. Then, it can perform subsequent operations on the target file data. That is, the whole process does not require the target file data to be transferred between the system layer and the logic layer, which can greatly reduce the amount of data communication.
[0201] By applying the embodiments of this application, it is possible to open a file once and perform multiple read or write operations, thereby reducing repetitive operations; it is also possible to read and write only a specified part of the target file each time to reduce invalid read and write operations; directly storing the target file data in the data buffer ArrayBuffer can reduce communication time; when performing frequent read and write operations on the target file, the read and write speeds will be faster, and the user experience of the mini-program or mini-game will be better.
[0202] It is understood that in the embodiments of this application, data such as user information are involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0203] The following description continues to illustrate the exemplary structure of the file processing device in the applet provided in this application embodiment as a software module. See [link to relevant documentation]. Figure 4 Client 242 includes:
[0204] The receiving module 41 is used to determine the address of the target file and the address of the data buffer corresponding to the target file when the logic layer of the mini-program receives a file access event for the target file; wherein the file access event is generated by the view layer of the mini-program based on the received file access operation for the target file;
[0205] The sending module 42 is used by the logic layer to send the address of the target file and the address of the data buffer to the system layer of the applet, wherein the system layer connects the logic layer and the view layer;
[0206] Storage module 43 is used by the system layer to call the file management interface based on the address of the target file to obtain the target data in the target file, and to store the target data in the data buffer based on the address of the data buffer; the target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
[0207] In some embodiments, the file processing device in the mini-program further includes a detection module, and the creation module is used to obtain the data size of the target data in the target file when the logic layer of the mini-program detects that there is no data buffer corresponding to the target file in memory; the logic layer creates the data buffer corresponding to the target file based on the data size of the target data.
[0208] In some embodiments, the detection module is further configured to detect the operation permissions corresponding to the data processing type of the target object performing the file access operation based on the data processing type indicated by the file access operation, and obtain a detection result; when the detection result indicates that the target object has operation permissions corresponding to the data processing type, the module determines the address of the data buffer corresponding to the target file.
[0209] In some embodiments, the storage module is further configured to obtain the size of the target data and the available capacity of the data buffer at the system layer; when the available capacity of the data buffer is greater than the size of the target data, the system layer stores the target data in the data buffer.
[0210] In some embodiments, the receiving module is further configured to have the logic layer of the mini-program parse the file access event to obtain the content operation parameters of the target file, wherein the content operation parameters are used to indicate the position of the target data in the target file; correspondingly, the storage module is further configured to have the system layer call the file management interface based on the address of the target file and the content operation parameters to obtain the target data in the target file; wherein the content operation parameters include at least one of the following: the content offset corresponding to the target data and the content length corresponding to the target data.
[0211] In some embodiments, the file management interface includes a file open interface and a file read interface. The storage module is further configured to have the system layer call the file open interface based on the address of the target file to open the target file and control the target file to be in an operable state; and the system layer call the file read interface based on the content operation parameters to read the target data from the data of the target file in the operable state.
[0212] In some embodiments, the content operation parameters include the content offset of the target data. The storage module is further configured to determine the start position of the content for the target data based on the address of the target file and the content offset; the system layer calls the file management interface to read data from the start position of the target data until the end position of the target file; and the data between the start position of the target data and the end position of the target file is taken as the target data.
[0213] In some embodiments, the content operation parameters include the content length of the target data. The storage module is further configured to determine the starting position of the content of the target file at the system layer; the system layer calls the file management interface to read data of the target length from the starting position of the content of the target file, and uses the data of the target length as the target data; wherein, the target length is equal to the content length of the target data.
[0214] In some embodiments, the content operation parameters include the content offset of the target data and the content length of the target data. The storage module is further configured to determine the starting position of the content for the target data based on the address of the target file and the content offset. The system layer calls the file management interface to read data of the target length from the starting position of the target data content and uses the data of the target length as the target data. The target length is equal to the file content length.
[0215] In some embodiments, the storage module is further configured to send a notification message from the system layer to the logic layer, the notification message indicating that the storage operation for the target data has been completed; the logic layer receives the notification message and performs a corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0216] In some embodiments, the storage module is further configured to, when the data processing type is data update, have the logic layer perform a corresponding data update operation on the target data in the data buffer and send an update instruction to the system layer; accordingly, after receiving the update instruction, the system layer obtains the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
[0217] In some embodiments, the storage module is further configured to have the logic layer periodically query the data buffer to obtain query results; when the query results indicate that the target data has been stored in the data buffer, the logic layer performs a corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
[0218] This application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the file processing method in the applet described above in this application embodiment.
[0219] This application provides a computer-readable storage medium storing executable instructions. When these executable instructions are executed by a processor, they cause the processor to execute a file processing method within a small program provided in this application. For example... Figure 3 The file handling methods shown in the mini-program.
[0220] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EP ROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0221] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0222] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0223] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.
[0224] In summary, the embodiments of this application eliminate the need for target data to be transferred between the logic layer and the system layer. Communication between the logic layer and the system layer can be achieved through instruction sending. This significantly reduces the amount of communication required for file access within the mini-program, improving file operation efficiency. Furthermore, if there are numerous file access operations on the target file during a single mini-program run, only one open and one close operation can be performed. This greatly reduces repetitive operations and increases the speed of file operations.
[0225] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A file processing method in a mini-program, characterized in that, The method includes: When the logic layer of the mini-program receives a file access event for the target file, it determines the address of the target file and the address of the data buffer corresponding to the target file. The file access event is generated by the view layer of the mini-program based on the received file access operation for the target file; the mini-program is a program that provides services in a hypertext markup language page, is downloaded by the client and immediately interpreted and executed, and does not require installation on the client. The logic layer sends the address of the target file and the address of the data buffer to the system layer of the mini-program, and the system layer connects the logic layer and the view layer; The system layer calls the file management interface based on the address of the target file to obtain the target data in the target file, and stores the target data in the data buffer based on the address of the data buffer; The target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
2. The method as described in claim 1, characterized in that, Before determining the address of the data buffer corresponding to the target file, the method further includes: When the logic layer of the mini-program detects that the data buffer corresponding to the target file does not exist in memory, it obtains the data size of the target data in the target file; The logic layer creates a data buffer corresponding to the target file based on the data size of the target data.
3. The method as described in claim 1, characterized in that, Determining the address of the data buffer corresponding to the target file includes: The logic layer detects the operation permissions of the target object executing the file access operation for the target file based on the data processing type indicated by the file access operation, and obtains the detection result; When the detection result indicates that the target object has operation permissions corresponding to the data processing type for the target file, the address of the data buffer corresponding to the target file is determined.
4. The method as described in claim 1, characterized in that, The step of storing the target data into the data buffer based on the address of the data buffer includes: The system layer obtains the size of the target data and the available capacity of the data buffer; When the available capacity of the data buffer is greater than the size of the target data, the system layer stores the target data in the data buffer.
5. The method as described in claim 1, characterized in that, The method further includes: The logic layer of the mini-program parses the file access event to obtain the content operation parameters of the target file. The content operation parameters are used to indicate the position of the target data in the target file. The system layer, based on the address of the target file, calls the file management interface to obtain the target data in the target file, including: The system layer calls the file management interface based on the address of the target file and the content operation parameters to obtain the target data in the target file; The content operation parameters include at least one of the following: the content offset corresponding to the target data and the content length corresponding to the target data.
6. The method as described in claim 5, characterized in that, The file management interface includes a file open interface and a file read interface. The system layer, based on the address of the target file and the content operation parameters, calls the file management interface to obtain the target data in the target file, including: The system layer, based on the address of the target file, calls the file opening interface to open the target file and controls the target file to be in an operable state; Based on the content operation parameters, the system layer calls the file reading interface to read the target data from the data of the target file, which is in an operable state.
7. The method as described in claim 5, characterized in that, The content operation parameters include the content offset of the target data. Based on the address of the target file and the content operation parameters, the system layer calls the file management interface to obtain the target data in the target file, including: The system layer determines the starting position of the content for the target data based on the address of the target file and the content offset; The system layer calls the file management interface to read data from the beginning of the target data content until the end of the target data content; The data between the start position of the target data content and the end position of the target file content is taken as the target data.
8. The method as described in claim 5, characterized in that, The content operation parameters include the content length of the target data. Based on the address of the target file and the content operation parameters, the system layer calls the file management interface to obtain the target data in the target file, including: The system layer determines the starting position of the content of the target file; The system layer calls the file management interface to read data of the target length from the beginning of the content of the target file, and uses the data of the target length as the target data; The target length is equal to the content length of the target data.
9. The method as described in claim 5, characterized in that, The content operation parameters include the content offset of the target data and the content length of the target data. Based on the address of the target file and the content operation parameters, the system layer calls the file management interface to obtain the target data in the target file, including: The system layer determines the starting position of the content for the target data based on the address of the target file and the content offset; The system layer calls the file management interface to read data of the target length from the beginning position of the target data content in the target file, and uses the data of the target length as the target data. The target length is equal to the content length of the target data.
10. The method as described in claim 1, characterized in that, After storing the target data in the data buffer based on the address of the data buffer, the method further includes: The system layer sends a notification message to the logic layer, the notification message indicating that the storage operation for the target data has been completed. The logic layer receives the notification message and performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
11. The method as described in claim 10, characterized in that, The step of performing a corresponding type of data operation on the target data based on the data processing type indicated by the file access operation includes: When the data processing type is data update, the logic layer performs the corresponding data update operation on the target data in the data buffer and sends an update instruction to the system layer; The method further includes: After receiving the update instruction, the system layer retrieves the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
12. The method as described in claim 1, characterized in that, The method further includes: The logic layer performs periodic data queries on the data buffer to obtain query results; When the query result indicates that the target data has been stored in the data buffer, the logic layer performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
13. A file processing device in a mini-program, characterized in that, The device includes: The receiving module is used to determine the address of the target file and the address of the corresponding data buffer when the logic layer of the mini-program receives a file access event for the target file; wherein, the file access event is generated by the view layer of the mini-program based on the received file access operation for the target file; the mini-program is a program that provides services in a hypertext markup language page, is downloaded by the client and immediately interpreted and executed, and does not require installation on the client. The sending module is used by the logic layer to send the address of the target file and the address of the data buffer to the system layer of the applet, wherein the system layer connects the logic layer and the view layer; The storage module is used by the system layer to call the file management interface based on the address of the target file to obtain the target data in the target file, and to store the target data in the data buffer based on the address of the data buffer; the target data in the data buffer is used by the logic layer to perform corresponding data operations on the target data based on the data processing type indicated by the file access operation.
14. The apparatus as claimed in claim 13, characterized in that, The device further includes a detection module, the detection module being used for: When the logic layer of the mini-program detects that the data buffer corresponding to the target file does not exist in memory, it obtains the data size of the target data in the target file; The logic layer creates a data buffer corresponding to the target file based on the data size of the target data.
15. The apparatus as claimed in claim 13, characterized in that, The device further includes a detection module for: The logic layer detects the operation permissions of the target object executing the file access operation for the target file based on the data processing type indicated by the file access operation, and obtains the detection result; When the detection result indicates that the target object has operation permissions corresponding to the data processing type for the target file, the address of the data buffer corresponding to the target file is determined.
16. The apparatus as claimed in claim 13, characterized in that, The storage module is also used for: The system layer obtains the size of the target data and the available capacity of the data buffer; When the available capacity of the data buffer is greater than the size of the target data, the system layer stores the target data in the data buffer.
17. The apparatus as claimed in claim 13, characterized in that, The receiving module is further configured to: The logic layer of the mini-program parses the file access event to obtain the content operation parameters of the target file. The content operation parameters are used to indicate the position of the target data in the target file. The storage module is also used for: The system layer calls the file management interface based on the address of the target file and the content operation parameters to obtain the target data in the target file; The content operation parameters include at least one of the following: the content offset corresponding to the target data and the content length corresponding to the target data.
18. The apparatus as claimed in claim 17, characterized in that, The file management interface includes a file open interface and a file read interface, and the storage module is further used for: The system layer, based on the address of the target file, calls the file opening interface to open the target file and controls the target file to be in an operable state; Based on the content operation parameters, the system layer calls the file reading interface to read the target data from the data of the target file, which is in an operable state.
19. The apparatus as claimed in claim 17, characterized in that, The content operation parameters include the content offset of the target data, and the storage module is further configured to: The system layer determines the starting position of the content for the target data based on the address of the target file and the content offset; The system layer calls the file management interface to read data from the beginning of the target data content until the end of the target data content; The data between the start position of the target data content and the end position of the target file content is taken as the target data.
20. The apparatus as claimed in claim 17, characterized in that, The content operation parameters include the content length of the target data, and the storage module is further configured to: The system layer determines the starting position of the content of the target file; The system layer calls the file management interface to read data of the target length from the beginning of the content of the target file, and uses the data of the target length as the target data; The target length is equal to the content length of the target data.
21. The apparatus as claimed in claim 17, characterized in that, The content operation parameters include the content offset of the target data and the content length of the target data. The storage module is further configured to: The system layer determines the starting position of the content for the target data based on the address of the target file and the content offset; The system layer calls the file management interface to read data of the target length from the beginning position of the target data content in the target file, and uses the data of the target length as the target data. The target length is equal to the content length of the target data.
22. The apparatus as claimed in claim 13, characterized in that, The storage module is also used for: The system layer sends a notification message to the logic layer, the notification message indicating that the storage operation for the target data has been completed. The logic layer receives the notification message and performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
23. The apparatus as claimed in claim 22, characterized in that, The storage module is also used for: When the data processing type is data update, the logic layer performs the corresponding data update operation on the target data in the data buffer and sends an update instruction to the system layer; After receiving the update instruction, the system layer retrieves the updated target data from the data buffer and performs a data update operation on the target file based on the updated target data.
24. The apparatus as claimed in claim 13, characterized in that, The storage module is also used for: The logic layer performs periodic data queries on the data buffer to obtain query results; When the query result indicates that the target data has been stored in the data buffer, the logic layer performs the corresponding type of data operation on the target data based on the data processing type indicated by the file access operation.
25. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable instructions; A processor, when executing executable instructions stored in the memory, implements the file processing method in the applet according to any one of claims 1 to 12.
26. A computer-readable storage medium storing executable instructions, characterized in that, When the executable instructions are executed by the processor, they implement the file processing method in the applet according to any one of claims 1 to 12.
27. A computer program product comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the file processing method in the applet according to any one of claims 1 to 12.
Citation Information
Patent Citations
A network disk system based on a multi-cloud server architecture
CN109583221A
Operating system cache file processing method
CN113626391A