Disclosure of Invention
The technical problem to be solved by the present invention is to provide a method and a system for creating and accessing a file, which can quickly access a larger file being created, aiming at the defects that in the prior art, when the file is accessed in the process of creating the larger file, the time spent by a client for obtaining the index information of the file is longer, so that the user has long waiting time and poor use experience.
The technical scheme adopted by the invention for solving the technical problems is as follows:
there is provided a method of file creation comprising the steps of:
creating a first file, wherein the first file is used for storing a file to be downloaded;
acquiring tail data of the file to be downloaded;
judging whether the file to be downloaded is a large file, if not, writing the file to be downloaded into the first file in sequence;
and if the file to be downloaded is a large file, creating a temporary file, writing the tail data into the temporary file, and sequentially downloading the file to be downloaded to the first file.
In the file creating method, when the data is downloaded to the tail data, the data in the temporary file is directly merged, and the temporary file is deleted.
In the file creating method of the present invention, the reference values of the sizes of the large file and the temporary file can be set according to the actual needs of the user.
The other technical scheme adopted by the invention for solving the technical problem is as follows:
a method for accessing files in a file creating process is provided, which comprises the following steps:
acquiring request information of a user for requesting to access a first file, wherein the first file is used for storing a file to be downloaded;
judging whether the file to be downloaded is a large file or not, and if not, directly reading the first file; if yes, further judging whether the downloading operation of the first file is finished;
if the downloading operation is finished, directly reading the first file; if the downloading operation is not finished, further judging whether the index information is at the end of the first file;
and if the index information is at the end of the first file, directly accessing a temporary file, wherein the temporary file is used for storing index data at the end of the file to be downloaded.
In the method for accessing the file in the file creating process, if the index information is not at the end of the first file, the first file is directly read.
The third technical scheme adopted by the invention for solving the technical problems is as follows:
constructing a file creation system comprising:
a first file creating unit for creating a first file; the first file is used for storing a file to be downloaded;
a last data acquiring unit, configured to acquire last data of the file to be downloaded;
the judging unit is used for judging whether the file to be downloaded is a large file;
the temporary file creating unit is used for creating a temporary file when the file to be downloaded is a large file;
the downloading unit is used for writing the files to be downloaded into the first file in sequence when the files to be downloaded are small files; or, when the file to be downloaded is a large file, the end data is written into the temporary file first, and then the file to be downloaded is sequentially downloaded to the first file.
In the file creating system of the present invention, the downloading unit is further configured to directly merge the data in the temporary file into the first file when downloading the last data of the large file;
the system also comprises a temporary file deleting unit which is used for deleting the temporary file after the downloading unit merges the data in the temporary file into the first file.
In the file creating system of the present invention, the reference values of the sizes of the large file and the temporary file are set according to the actual needs of the user.
The fourth technical scheme adopted by the invention for solving the technical problems is as follows:
a system for accessing files in a file creation process is constructed, and comprises:
the device comprises a request information acquisition unit, a download unit and a download unit, wherein the request information acquisition unit is used for acquiring request information of a user for requesting to access a first file, and the first file is used for storing a file to be downloaded;
the first judging unit is used for judging whether the file to be downloaded is a large file;
a second judging unit, configured to further judge whether the downloading operation of the first file is completed when the first judging unit judges that the file to be downloaded is a large file;
a first file reading unit, configured to directly read the first file when the determination result of the first determining unit is that the file to be downloaded is not a large file, or when the determination result of the second determining unit is that the downloading operation of the file to be downloaded is completed;
a third determining unit, configured to further determine whether index information is at the end of the first file when a determination result of the second determining unit is that the downloading operation of the first file is not completed;
and the temporary file reading unit is used for directly reading the temporary file when the judgment result of the third judging unit is that the index information is at the end of the first file, and the temporary file is used for storing the end data of the file to be downloaded.
In the system for accessing a file in the file creating process of the present invention, the first file reading unit is further configured to directly read the first file when the judgment result of the third judging unit is that the index information is not at the end of the first file.
The fifth technical scheme adopted by the invention for solving the technical problems is as follows:
an overall system for file creation and access is constructed, including the file creation system described above and the system for accessing files during file creation.
The invention has the following beneficial effects: in the invention, in the file creating process, if the file to be downloaded is a large file, a temporary file is established for storing the tail data of the file to be downloaded, and when the video file is accessed in the downloading process, the temporary file can be directly accessed first, because the index data of the general video file is at the tail of the file, the index file can be quickly found, the video file is played and dragged to a certain playing position, and the waiting time of a user is reduced.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, the method for creating a file according to an embodiment of the present invention includes the following steps:
s101, creating a first file, wherein the first file is used for storing a file to be downloaded; in this embodiment, taking video on demand as an example, when a user sends an on demand request during video on demand, the system starts to create a file for storing a video file to be downloaded;
s102, acquiring tail data of a file to be downloaded; the index information of a general video file is at the tail of the file, before downloading the file, the tail data of the file to be downloaded can be acquired firstly, and can be temporarily stored in a memory of a system and not written into a hard disk temporarily; the size of the last data of the file to be downloaded can be set to different values according to the requirement, and the size of the index information of the video file generally does not exceed 2 Mbytes, so that the data of 2 Mbytes at the end of the file to be downloaded can be generally obtained.
S103, judging whether the file to be downloaded is a large file; after the system establishes the download link through the network according to the request of the user, a file for storing the download information is generally established, the file comprises the information such as the size of the file to be downloaded, and the size of the file to be downloaded can be judged according to the content in the file. Setting a reference value for comparison can be realized, for example, 100M, 200M, etc. can be set according to needs. Generally, a file with more than 100 megabytes can be regarded as a large file, and if the reference value can be set to be 100M, the file to be downloaded is regarded as the large file when the file to be downloaded is more than 100M; when the file to be downloaded is less than 100M, the file is considered to be a small file.
S104, if the file to be downloaded is a small file, sequentially writing the file to be downloaded into a first file; that is, if the file is a small file, the file to be downloaded is sequentially written into the created file according to the normal downloading sequence, as in the first file in this embodiment, because the file is not large, even if the index information is at the end, the index information of the file can be quickly acquired.
And S105, if the file to be downloaded is a large file, creating a temporary file, and writing the tail data into the temporary file, wherein the size of the temporary file generally does not exceed 2 megabytes, which is based on the size of the index information of the video file, and the size of the temporary file in the embodiment is 2M, that is, the tail data of the file to be downloaded, namely 2M, can be stored. The optimized large file can be created by creating the temporary file, when a user requests to access the video file, if the video file is large, the index information of the video file can be quickly obtained by firstly obtaining the temporary file, and therefore the video file can be quickly and directly played or dragged to a certain playing position in the downloading process.
S106, after writing the tail data into the temporary file, sequentially downloading the file to be downloaded to the first file;
s107, directly combining the data in the temporary file when the tail data is downloaded;
further, the method for creating a file according to the embodiment of the present invention further includes step S108, after the file downloading operation is completed, the temporary file may be deleted, so as to save the storage space.
As shown in fig. 3, the file creating system according to the embodiment of the present invention mainly includes a first file creating unit 10, a first file 20, an end data obtaining unit 30, a judging unit 40, a downloading unit 50, a temporary file creating unit 60, a temporary file 70, and a temporary file deleting unit 80. Wherein,
a first file creating unit 10, configured to create a first file 20, where the first file 20 is used to store a file to be downloaded; still taking video on demand as an example, when a user sends an on demand request during video on demand, the file creation system starts to create a first file for storing a video file to be downloaded.
A last data acquiring unit 30 for acquiring last data of the file to be downloaded; the last data is generally retrieved no more than 2 mbytes.
A judging unit 40, configured to judge whether a file to be downloaded is a large file; after establishing a download link through a network according to a user's request on demand, a general file creation system establishes a file for storing download information, the file includes information such as the size of the file to be downloaded, and the size of the file to be downloaded can be determined according to the content in the file. Typically files above 100 megabytes can be considered large files.
The temporary file creating unit 60 is configured to create a temporary file 70 when the file to be downloaded is a large file, and write the last data into the temporary file 70 through the downloading unit 50, where the size of the temporary file 70 generally does not exceed 2 mbytes; when a user requests to access a video file, if the video file is large, the index information of the video file can be quickly acquired by acquiring the temporary file 70, so that the video file can be quickly and directly played or dragged to a certain playing position in the downloading process.
A downloading unit 50, configured to, when the determination result of the determining unit 40 is that the file to be downloaded is a small file, sequentially write the files to be downloaded into the first file 20; or, when the judgment unit 40 judges that the file to be downloaded is a large file, the last data is written into the temporary file 70, and then the file to be downloaded is sequentially downloaded to the first file 20.
Further, in the file creating system according to the embodiment of the present invention, the downloading unit 50 is further configured to directly merge the data in the temporary file 70 into the first file 20 when downloading the last data of the large file; the system further comprises a temporary file deleting unit 80, configured to delete the temporary file 70 after the downloading unit 50 merges the data in the temporary file 70 into the first file 20, because after the downloading of the file to be downloaded is completed, the user can directly perform the video on demand locally, the response speed is fast, and the access speed is increased without using the temporary file 70. Deleting the temporary file 70 can clean up the storage space in time.
The embodiment mainly describes the process of file creation and storage optimization by taking a large file as an example, and is used for explaining the basic principle of the invention and showing the technical effect of obviously improving the user experience. In theory, the method can be used for optimizing the downloading of files with any size.
As shown in fig. 2, the method for accessing a file in a file creation process according to an embodiment of the present invention mainly includes the following steps:
s201, acquiring request information of a user for requesting to access a first file, wherein the first file is used for storing a file to be downloaded; also taking video on demand as an example, the first file is consistent with the above first file, i.e. the video file that the user wants to request.
S202, judging whether the file to be downloaded is a large file; generally, a file with more than 100 megabytes can be regarded as a large file, and how to determine whether the file to be downloaded is the large file has been described in the above embodiments, and details are not repeated here.
S203, if the file to be downloaded is not a large file, directly reading the first file;
s204, if the file to be downloaded is a large file, further judging whether the downloading operation of the first file is finished; if the downloading operation is completed, directly reading the first file, namely entering into step S203;
s205, if the downloading operation is not finished, further judging whether the index information is at the end of the first file; generally, different players can play files in the same format, and the index information of the file is either at the head of the playing file or at the tail of the playing file, so that whether the index information is at the head or the end of the playing file can be judged.
S206, if the index information is not at the end of the first file, directly reading the first file, namely, entering to execute the step S203, wherein the index information which is not the file and is stored in the temporary file in this case is obtained by directly reading the downloaded file header of the first file; if the index information is at the end of the first file, directly accessing a temporary file (the temporary file is the same as the above temporary file, and detailed description is not expanded herein), wherein the temporary file is used for storing index data at the end of the file to be downloaded; the index information of the large file is acquired by accessing the temporary file, so that the waiting time of a user can be greatly reduced, the video file can be smoothly watched while downloading, or the video file is dragged to a certain playing position, and the user experience is improved.
As shown in fig. 4, the system for accessing files in the file creation process according to the embodiment of the present invention mainly includes: a request information acquisition unit 21, a first judgment unit 22, a second judgment unit 23, a first file reading unit 24, a third judgment unit 25, and a temporary file reading unit 26; wherein,
a request information obtaining unit 21, configured to obtain request information for requesting a user to access a first file, where the first file is used to store a file to be downloaded;
the first determining unit 22 is configured to determine whether a file to be downloaded is a large file, where a file with more than 100 megabytes can be regarded as a large file, and how to determine the large file is described in detail above, which is not described herein again;
a second judging unit 23, configured to further judge whether the downloading operation of the first file is completed when the first judging unit 22 judges that the file to be downloaded is a large file;
a first file reading unit 24, configured to directly read the first file when the determination result of the first determining unit 22 is that the file to be downloaded is not the large file, or when the determination result of the second determining unit 23 is that the downloading operation of the file to be downloaded has been completed;
a third judging unit 25, configured to further judge whether the index information is at the end of the first file when the judgment result of the second judging unit 23 is that the downloading operation of the first file is not completed; generally, different players can play files in the same format, and the index information of the file is either at the head of the playing file or at the tail of the playing file, so that whether the index information is at the head or the end of the playing file can be judged.
A temporary file reading unit 26, configured to, when the judgment result of the third judging unit 25 is that the index information is at the end of the first file, directly read a temporary file (where the temporary file is the same as the above temporary file, and detailed description is not given here), where the temporary file is used to store the end data of the file to be downloaded. The index information of the large file is acquired by accessing the temporary file, so that the waiting time of a user can be greatly reduced, the video file can be smoothly watched while downloading, or the video file is dragged to a certain playing position, and the user experience is improved.
Further, the first file reading unit 24 is also configured to directly read the first file when the judgment result of the third judging unit 25 is that the index information is not at the end of the first file.
The embodiment of the invention also provides a total system for file creation and access, which comprises the file creation system and the system for accessing the file in the file creation process in the embodiment. The specific structure of the file creation system and the system for accessing the file in the file creation process are not described herein again, and reference may be made to the above-described embodiments.
In the invention, in the process of creating the first file, if the file to be downloaded is a large file, a temporary file is established for storing the tail data of the file to be downloaded, and when the video file is accessed in the downloading process, the temporary file can be directly accessed first, because the index data of the general video file is at the tail of the file, the index file can be quickly found, the video file is played and dragged to a certain playing position, and the waiting time of a user is reduced.
It will be understood that modifications and variations can be made by persons skilled in the art in light of the above teachings and all such modifications and variations are intended to be included within the scope of the invention as defined in the appended claims.