Disclosure of Invention
The invention provides a file generation method, a file generation device, electronic equipment and a storage medium, and aims to solve the technical problem that the response speed of a browser is low due to the fact that multiple reading operations are required in the existing positioning method.
In a first aspect, the present invention provides a file generating method, including:
acquiring a target word stock according to a user request; wherein the user request comprises: the target font and a plurality of target file formats, wherein the target font library comprises the target font;
calling a script to enable the target word stock to generate a plurality of target files; the file formats of the target files correspond to the target file formats one by one;
and writing the plurality of target files into a second storage medium.
Optionally, the obtaining the target word stock according to the user request includes:
reading a full word stock from a third storage medium;
and extracting the target word stock from the full word stock according to the user request.
Optionally, the reading the full word stock from the third storage medium specifically includes:
determining whether the whole word library is stored in a cache;
and if the full word stock is determined to be stored in the cache, reading the full word stock from the cache.
Optionally, if it is determined that the full word stock does not exist in the cache, reading the full word stock from a disk.
Optionally, after the reading the full word library from the third storage medium, the method further includes:
and writing the full word bank into the cache.
In a second aspect, the present invention provides a file generating apparatus, including:
the reading module is used for acquiring a target word stock according to a user request; wherein the user request comprises: the target font and a plurality of target file formats, wherein the target font library comprises the target font;
the generating module is used for calling a script to enable the target word stock to generate a plurality of target files; the file formats of the target files correspond to the target file formats one by one;
and the writing module is used for writing the target files into a second storage medium.
Optionally, the apparatus further comprises: an extraction module;
the reading module is also used for reading the full word stock from a third storage medium;
the extraction module is used for extracting the target word stock from the full word stock according to the user request.
Optionally, the reading module is specifically configured to:
determining whether the whole word stock exists in a cache;
and if the full word stock is determined to be stored in the cache, reading the full word stock from the cache.
Optionally, the reading module is specifically configured to:
and if the cache does not have the full word stock, reading the full word stock from a disk.
Optionally, the writing module is further configured to:
and writing the full word bank into the cache.
In a third aspect, the present invention provides a file generating apparatus, including:
a memory for storing a program;
a processor for executing the program stored in the memory, the processor being configured to perform the file generation method according to the first aspect and the alternative when the program is executed.
In a fourth aspect, the present invention provides a computer-readable storage medium comprising instructions which, when executed on a computer, cause the computer to perform the file generation method according to the first aspect or the alternative.
The embodiment of the invention provides a file generation method, a file generation device, electronic equipment and a storage medium, wherein the method comprises the following steps: and acquiring a target font library containing target fonts, calling corresponding scripts to enable the target font library to generate target files with various different formats, and writing the target files into a second storage medium. According to the method provided by the invention, after the target word stock is obtained, a plurality of target files are generated according to the target word stock and are stored in the second storage medium together, so that the reading and writing times of an IO port are reduced, and the response speed of the browser is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
When a user uses the browser, a user request for generating files with different formats is sent, the server calls a target word stock from the disk according to the user request in order to respond to the user request, calls corresponding format conversion scripts to generate corresponding format files, the format files are sequentially stored in the disk, and the process is repeated to generate files with multiple formats. However, when generating a file with multiple formats, the existing file generation method needs to perform multiple reading operations, and the response rate of the browser is reduced because the reading and writing operations are time-consuming.
Aiming at the problems in the prior art, the invention provides a file generation method, a file generation device, electronic equipment and a storage medium, so as to improve the response speed of a browser.
The following file formats are commonly used at present:
TTF: TTF (full name: trueTypeFont) is a font file format commonly introduced by Apple and Microsoft companies, and has become one of the most common font file representation modes with the popularity of windows.
WOFF: the Web Open Font Format (Web Open Font Format, abbreviated as WOFF) is a Font Format standard adopted by a Web page.
SVG: scalable Vector Graphics (SVG) is an XML-based two-dimensional Vector Graphics standard introduced by the World Wide Web Consortium (W3C).
EOT: a compressed word stock aims to solve the problem of embedding special fonts in a webpage. EOT fonts are currently supported only by microsoft's IE browser.
FIG. 1 is a diagram illustrating a system architecture according to an exemplary embodiment of the present invention. As shown in fig. 1, the system on which the file generation method provided by the present invention is based includes: a client device 101 and a server 102.
The user browses a web page by using a browser on the client device 101, and the client device 101 sends a user request to the server, wherein the user request comprises a target font and a plurality of file formats. After receiving the user request, the server 102 reads a target font library containing a target font, generates target files in multiple file formats, and sends a storage path of the target files to the client device 102, so that the client re-sends the user request according to the storage path, wherein the re-sent user request contains the storage path of the target file to be quoted, after obtaining the target file according to the storage path, the server sends the target file to the client device, and the client device loads the corresponding target file on a corresponding page in the browser.
FIG. 2 is a flowchart illustrating a file generation method according to an exemplary embodiment of the invention. As shown in fig. 2, the present invention provides a file generation method, including:
s201, acquiring a target word stock according to a user request.
More specifically, when a user browses a web page using a browser, the user requests an instruction to the server. The user request instruction comprises a target word stock required to be displayed by the user and a file format supported by the browser.
The server acquires the target word stock according to the user request so that the server can process the target word stock to generate a file with a corresponding format. Wherein the target font library comprises the target font requested in the user request.
S202, calling the script to enable the target word stock to generate a plurality of target files.
More specifically, after obtaining the target word stock, the server calls the corresponding script file to generate the corresponding target file. The file formats of the target files correspond to the target file formats one by one. Now, the following examples are given:
the method comprises the steps that a user requests to generate a target file in a TTF format and a target file in a WOFF format, a server calls a script file after obtaining a target word stock, the file in the TTF format and the file in the WOFF format are set in parameters of the script file, the script is operated, and the target file in the TTF format and the target file in the WOFF format are generated.
The method comprises the steps that a user requests to generate target files in a TTF format, a WOFF format, an SVG format and an EOT format, a server calls a script file after obtaining a target word stock, sets a file for generating the TTF format, a file for generating the WOFF format and a file for generating the EOT format in parameters of the script file, runs the script and generates the target files in the TTF format, the WOFF format and the EOT format. And calling the script file again, setting a file for generating an SVG format in the parameters of the script file, calling the script file, and generating a target file of the SVG format.
And S203, writing the plurality of target files into a second storage medium.
More specifically, after obtaining the plurality of object files, the object files are stored in the second storage medium. Wherein the second storage medium is a magnetic disk.
The principles of the document generation method are described in detail below: after receiving the user request, the server acquires the target word stock according to the user request, processes the target word stock, generates the target file corresponding to the file format required by the user request, and does not involve reading and writing the disk by using the IO interface in the process of generating a plurality of target files by using the target word stock, but the reading and writing of the disk by using the IO interface is time-consuming, so that the response time of the server can be reduced.
In the file generating method provided in this embodiment, a target font library including a target font is first obtained, a corresponding script is then called, so that the target font library generates a plurality of target files in different formats, and finally the plurality of target files are written in a second storage medium. According to the file generation method provided by the invention, after the target word stock is obtained, a plurality of target files are generated according to the target word stock and are stored in the second storage medium together, so that the reading and writing times of an IO port are reduced, and the response speed of a browser is improved.
Fig. 3 is a flowchart illustrating a file generation method according to another exemplary embodiment of the present invention. As shown in fig. 3, the file generation method provided by the present invention includes:
s301, determining whether the cache stores a full word stock. If the cache is determined to store the full word stock, the S302 is entered; otherwise, S303 is entered.
More specifically, the full word library refers to a database containing all chinese characters, all english letters, and other special characters, and the full word library has a huge data size. In this embodiment, if the client device sends the user request for the first time, the full word stock does not necessarily exist in the cache, and the full word stock needs to be read from the disk through the IO interface. And if the client device does not send the user request for the first time and the full word library is already added into the cache, directly reading the full word library in the cache.
S302, reading the full word stock from the cache, and entering S305.
More specifically, if the client device does not send the user request for the first time, the third storage medium is a cache, and the full word stock is directly read from the cache.
And S303, reading the full word stock from the disk.
More specifically, if the client device sends the user request for the first time and the third storage medium is a disk, the full word stock needs to be read from the disk through the IO port.
And S304, writing the full word bank into the cache.
More specifically, if the client device sends the user request for the first time, the full word bank is written into the cache for use in receiving the next user request.
S305, extracting the target word stock from the full word stock according to the user request.
More specifically, the number of target fonts requested by the client device is limited compared to the amount of data in the full word stock, and there is no need to format convert the full word stock, and therefore, the target word stock containing the target fonts is extracted from the full word stock.
S306 to S308 are the same as S201 to S203 in the file generation method provided in the embodiment shown in fig. 2, and are not described again here.
The working principle of the file generation method provided by the embodiment is described in detail below: whether a full-word library file exists in a cache or not is determined, if the full-word library file does not exist in the cache, the full-word library is stored in the cache after the full-word library file is obtained, the situation that the full-word library file needs to be read from a magnetic disc when a server responds to each request of client equipment is avoided, a target word library is generated according to the full-word library after the full-word library is obtained, a plurality of target files with different formats are generated according to the target word library, reading and writing of the magnetic disc by using an IO interface are not involved in the process of generating the plurality of target files by using the target word library, the processing time of the server is shortened in two links, and the response speed of the server is improved.
In the file generation method provided in this embodiment, if the user request is initiated for the first time, the full word stock is directly stored in the cache after the full word stock is read from the disk, so that the full word stock is directly read from the cache when the full word stock is utilized next time, and if the user request is not initiated for the first time, the full word stock is directly read from the cache. By caching the full word stock, the time for reading the full word stock is reduced, the response speed of the browser is improved, and the user experience is improved.
Fig. 4 is a flowchart of a file generation method according to another exemplary embodiment of the present invention, and as shown in fig. 4, the file generation method provided by the present invention includes the following steps:
s401, receiving a user request.
More specifically, the server receives a user request from a client, such as: the target font requested by the client is 'hello China', and the target file format is TTF format, WOFF format, SVG format and EOT format.
S402, determining whether the corresponding file is stored in the cache.
More specifically, the server determines whether a file exists in the cache, the file includes the target font, and the file format is the target file format. For example: and determining whether the files in the TTF format, the WOFF format, the SVG format and the EOT format exist in the cache, wherein the files comprise 'hello China'.
And S403, if the file containing the target font corresponding to the target file format exists in the cache, directly outputting a storage path of the target file in the server, otherwise, entering S404.
S404, whether the cache stores the full word stock or not is determined. If the cache is determined to store the full word stock, the process goes to S405; otherwise, S406 is entered.
S405, reading the full word bank from the cache, and entering 408.
S406, reading the full word stock from the disk.
More specifically, if the full word stock is not stored in the cache, the full word stock is read from the disk through the IO interface.
And S407, writing the full word bank into the cache.
And S408, extracting the target word stock from the full word stock according to the user request.
More specifically, a target font library including a target font is extracted from the full font library according to a user request. For example: extracting a target word stock containing 'your Chinese'.
And S409, acquiring a target word stock according to the user request.
More specifically, the target word stock is obtained according to a user request, for example: and acquiring a target word stock containing 'hello China' according to the user request.
And S410, calling the script to enable the target word stock to generate a plurality of target files.
More specifically, the script is executed to cause the target word stock to generate a plurality of target files. For example: after obtaining a target word stock containing 'hello China', the server calls the script file, sets a file for generating a TTF format, a file for generating a WOFF format and a file for generating an EOT format in parameters of the script file, runs the script and generates target files for generating the TTF format, the WOFF format and the EOT format. And calling the script file again, setting a file in an SVG format in the parameters of the script file, calling the script file, and generating a target file in the SVG format.
S411, writing the plurality of target files into a second storage medium.
More specifically, the object file is stored in the second storage medium. Wherein the second storage medium may be a magnetic disk. For example: and storing the target files in the TTF format, the WOFF format, the SVG format and the EOT format into a disk or a cache.
According to the file generation method provided by the embodiment, after the target word stock is obtained, a plurality of target files are generated according to the target word stock and are stored in the second storage medium together, so that the reading and writing times of an IO port are reduced, and the response speed of a browser is improved.
The following describes a file generation apparatus, which has similar implementation principles and technical effects to those of the above method, and is not described herein again.
Fig. 5 is a schematic structural diagram of a file generation apparatus according to an exemplary embodiment of the present invention. As shown in fig. 5, the present invention provides a file generation apparatus, the apparatus 500 comprising:
a reading module 501, configured to obtain a target word stock according to a user request; wherein the user request comprises: the target font and a plurality of target file formats, wherein the target font library comprises the target font;
a generating module 502, configured to invoke a script to enable the target word stock to generate a plurality of target files; the file format of the target file corresponds to the target file format one by one.
Optionally, the apparatus further comprises: an extraction module 504;
the reading module 501 is further configured to read a full word stock from a second storage medium;
the extraction module 504 is configured to extract a target word stock from the full word stock according to a user request.
Optionally, the reading module 501 is specifically configured to:
determining whether a full word stock exists in the cache;
and if the full word stock is determined to be stored in the cache, reading the full word stock from the cache.
Optionally, the reading module is specifically configured to:
and if the cache does not have the full word stock, reading the full word stock from the disk.
Optionally, the writing module 503 is further configured to:
the full word bank is written into the cache.
Fig. 6 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention, and as shown in fig. 6, an electronic device 600 provided in this embodiment includes: a processor 601 and a memory 602.
A memory 602 for storing computer-executable instructions;
the processor 601 is configured to execute the computer execution instructions stored in the memory to implement the steps performed by the file generation method in the foregoing embodiments. Reference may be made specifically to the related description in the foregoing control method embodiment.
Alternatively, the memory 602 may be separate or integrated with the processor 601.
When the memory 602 is separately provided, the electronic device further includes a bus 603 for connecting the memory 602 and the processor 601.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer execution instruction is stored in the computer-readable storage medium, and when the processor executes the computer execution instruction, the file generation method implemented by the electronic device is implemented.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.