CN110784756B - File reading method and device, computing equipment and storage medium - Google Patents

File reading method and device, computing equipment and storage medium Download PDF

Info

Publication number
CN110784756B
CN110784756B CN201911401308.6A CN201911401308A CN110784756B CN 110784756 B CN110784756 B CN 110784756B CN 201911401308 A CN201911401308 A CN 201911401308A CN 110784756 B CN110784756 B CN 110784756B
Authority
CN
China
Prior art keywords
data
current
file offset
data volume
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911401308.6A
Other languages
Chinese (zh)
Other versions
CN110784756A (en
Inventor
不公告发明人
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhuhai Eeasy Electronic Tech Co ltd
Original Assignee
Zhuhai Eeasy Electronic Tech Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhuhai Eeasy Electronic Tech Co ltd filed Critical Zhuhai Eeasy Electronic Tech Co ltd
Priority to CN201911401308.6A priority Critical patent/CN110784756B/en
Publication of CN110784756A publication Critical patent/CN110784756A/en
Application granted granted Critical
Publication of CN110784756B publication Critical patent/CN110784756B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/433Content storage operation, e.g. storage operation in response to a pause request, caching operations
    • H04N21/4331Caching operations, e.g. of an advertisement for later insertion during playback
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/83Generation or processing of protective or descriptive data associated with content; Content structuring
    • H04N21/845Structuring of content, e.g. decomposing content into time segments
    • H04N21/8456Structuring of content, e.g. decomposing content into time segments by decomposing the content in the time domain, e.g. in time segments

Abstract

The invention is suitable for the technical field of computers, and provides a file reading method, a file reading device, a computing device and a storage medium, wherein the method comprises the following steps: judging whether the first data volume is smaller than a second data volume, wherein the first data volume is the data volume corresponding to the data reading request, the second data volume is the data volume corresponding to the unread data in the current memory, if not, returning the unread data in the memory as first return data, judging whether the unreturned data volume is integral multiple of a preset data volume, otherwise, reading the data of a third data volume from the file, returning the read data of the third data volume as second return data, reading the data of the preset data volume from the file and storing the data in the memory, reading the data of a fourth data volume from the memory as third return data and returning the data, reading the data from the memory preferentially, updating cache data in the memory according to the data volume corresponding to the data reading request, and improving the reading efficiency of the file.

Description

File reading method and device, computing equipment and storage medium
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a file reading method and device, computing equipment and a storage medium.
Background
In the process of reading a file, especially in the process of reading a file during video playing, data is usually read directly from the file, but the process of reading data directly from the file is a time-consuming process.
In the video playing process, a user wants to skip the middle segment and directly play the video from a certain time point, the position corresponding to the time point is the video playing starting position, the operation process is called seek, and a time-consuming process is directly performed from a certain position seek to another position in the file.
During video playing, we need to stream the video file into separate audio data and video data. Meanwhile, seek will frequently read data to different positions in the file. The method can influence the shunting speed of the audio and video, thereby reducing the fluency of video playing and giving people a feeling of blocking.
Disclosure of Invention
The invention aims to provide a file reading method, a file reading device, a computing device and a storage medium, and aims to solve the problem of low data reading efficiency caused by directly reading data from a file in the prior art.
In one aspect, the present invention provides a file reading method, including the steps of:
judging whether a first data volume is smaller than a second data volume, wherein the first data volume is a data volume corresponding to a data reading request, and the second data volume is a data volume corresponding to unread data in a current preset memory;
if not, returning the unread data in the preset memory as first return data, and updating the current file offset;
judging whether the unreturned data volume is integral multiple of the preset data volume or not;
if not, reading data of a third data volume from the file according to the current file offset, returning the read data of the third data volume as second return data, reading the data of the preset data volume from the file, storing the data of the preset data volume into the preset memory, and updating the current file offset, wherein the third data volume is the product of the unreturned data volume divided by the preset data volume and then rounded down;
and reading data of a fourth data volume from the preset memory as third return data to be returned, and updating the current file offset and the second data volume, wherein the fourth data volume is the difference between the unreturned data volume and the third data volume.
Preferably, after the step of determining whether the first data amount is smaller than the second data amount, the method includes:
if the current file offset is smaller than the second data volume, reading the data of the first data volume from the preset memory as return data, and updating the current file offset and the second data volume;
after the step of judging whether the unreturned data volume is an integral multiple of the predetermined data volume, the method comprises the following steps:
and if the number of the data is integral multiple, reading the data of the unreturned data volume from the file according to the current file offset, returning the read data of the unreturned data volume as second returned data, reading the data of the preset data volume from the file, storing the data of the preset data volume into the preset memory, and updating the current file offset and the second data volume.
Preferably, after the step of reading the data with the predetermined data size from the file and storing the data in the preset memory, the method includes:
updating the current minimum file offset and the current maximum file offset, wherein the current minimum file offset and the current maximum file offset correspond to the initial position and the final position of the data stored in the preset memory in the file, and the difference between the current maximum file offset and the current minimum file offset is the preset data volume.
Preferably, the method further comprises:
when the seek operation is executed, judging whether the target position is at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset;
if so, updating the current file offset and the second data volume;
and if not, reading the data with the preset data volume from the file according to the target position, storing the data into the preset memory, and updating the current file offset, the current minimum file offset, the current maximum file offset and the second data volume.
In another aspect, the present invention provides a document reading apparatus, including:
the data volume judging unit is used for judging whether a first data volume is smaller than a second data volume, wherein the first data volume is a data volume corresponding to a data reading request, and the second data volume is a data volume corresponding to unread data in a current preset memory;
a first returning unit, configured to return, if the first data amount is not smaller than the second data amount, the unread data in the preset memory as first returned data, and update the current file offset;
a multiple judgment unit for judging whether the unreturned data amount is an integral multiple of the predetermined data amount;
a second returning unit, configured to, if the unreturned data amount is not an integer multiple of the predetermined data amount, read data of a third data amount from the file according to the current file offset, return the read data of the third data amount as second returned data, read data of the predetermined data amount from the file, store the data in the preset memory, and update the current file offset, where the third data amount is a product of the unreturned data amount divided by the predetermined data amount and then rounded down by the predetermined data amount; and
and a third returning unit, configured to read data of a fourth data size from the preset memory as third returned data, and return the third returned data, and update the current file offset and the second data size, where the fourth data size is a difference between the unreturned data size and the third data size.
Preferably, the apparatus further comprises:
a fourth returning unit, configured to, if the first data size is smaller than the second data size, read data of the first data size from the preset memory as a return data, and return the return data, so as to update the current file offset and the second data size; and
and a fifth returning unit, configured to, if the unreturned data amount is an integral multiple of the predetermined data amount, read the unreturned data amount from the file according to the current file offset, return the read unreturned data amount as second returned data, read the predetermined data amount from the file, store the data in the preset memory, and update the current file offset and the second data amount.
Preferably, the apparatus further comprises:
and the file offset updating unit is used for updating the current minimum file offset and the current maximum file offset, the current minimum file offset and the current maximum file offset correspond to the initial position and the final position of the data stored in the preset memory in the file, and the difference between the current maximum file offset and the current minimum file offset is the preset data volume.
Preferably, the apparatus further comprises:
the position judging unit is used for judging whether the target position is positioned at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset when the seek operation is executed;
a first execution unit, configured to update the current file offset and the second data size if the target location is located at a current minimum file offset location or between the current minimum file offset location and a current maximum file offset location; and
a second execution unit, configured to, if the target location is not located at the current minimum file offset location and is not located between the current minimum file offset location and the current maximum file offset location, read, according to the target location, the data of the predetermined data size from the file and store the data in the preset memory, and update the current file offset, the current minimum file offset, the current maximum file offset, and the second data size.
In another aspect, the present invention also provides a computing device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method as described above when executing the computer program.
In another aspect, the present invention also provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method as described above.
The invention judges whether a first data volume is smaller than a second data volume, the first data volume is the data volume corresponding to a data reading request, the second data volume is the data volume corresponding to the unread data in the current preset memory, if not, the unread data in the preset memory is returned as a first return data, judges whether the unreturned data volume is integral multiple of the preset data volume, if not, reads the data of a third data volume from the file, returns the read data of the third data volume as a second return data, reads the data of the preset data volume from the file and stores the data in the preset memory, reads the data of a fourth data volume from the preset memory and returns the data as a third return data, thereby preferentially reading the data from the memory and updating the cache data in the memory according to the data volume corresponding to the data reading request, the reading efficiency of the file is improved.
Drawings
Fig. 1 is a flowchart illustrating an implementation of a file reading method according to an embodiment of the present invention;
fig. 2 is a flowchart of an implementation of a file reading method according to a second embodiment of the present invention;
fig. 3 is a flowchart of an implementation of a file reading method according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a file reading apparatus according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of a file reading apparatus according to a fifth embodiment of the present invention; and
fig. 6 is a schematic structural diagram of a computing device according to a sixth embodiment of the present invention.
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.
The following detailed description of specific implementations of the present invention is provided in conjunction with specific embodiments:
the first embodiment is as follows:
fig. 1 shows an implementation flow of a file reading method provided in a first embodiment of the present invention, and for convenience of description, only a part related to the first embodiment of the present invention is shown, and the details are as follows:
in step S101, it is determined whether the first data amount is smaller than the second data amount.
The embodiment of the invention is suitable for computing equipment, in particular to video playing equipment. In the embodiment of the present invention, a Memory space with a preset size is pre-partitioned from a Memory space of the file reading device to cache file data, where the Memory is a Random Access Memory (RAM), and the size of the preset Memory space may be set according to needs, for example, 2M, and of course, the size of the preset Memory space may also be adjusted according to a hardware condition of the file reading device or an actual user requirement condition, which is not limited herein.
In the embodiment of the present invention, the first data amount is a data amount corresponding to the data read request, and the second data amount is a data amount corresponding to data that is not read in the current preset memory. For convenience of description, in the embodiment of the present invention, a first data amount is represented by N, a data amount of unread data in a preset memory is represented by P, a storage capacity of the preset memory and a predetermined data amount are represented by T, a current minimum file offset is represented by min _ off, a current maximum file offset is represented by max _ off, and a current file offset is represented by cur _ off, where P ≦ T.
In step S102, if not, returning unread data in the preset memory as the first return data, and updating the current file offset.
In the embodiment of the present invention, if the first data amount is greater than or equal to the second data amount, that is, N is greater than or equal to P, the unread data in the preset memory is returned as the first data, that is, the data of P is returned first, the updated current file offset is the sum of the file offset before updating and the data read from the preset memory, that is, cur _ off = cur _ off + P, further, the first data amount and the second data amount are updated, the updated first data amount is the difference between the first data amount before updating and the data amount of the data read from the preset memory, and the updated second data amount is zero, that is, N = N-P, and P = 0.
For example, if the first data volume N is 4M, the data volume P of the unread data in the preset memory is 0.5M, and the predetermined data volume is 2M, the unread 0.5M data in the preset memory is returned as the first return data, and the file offset and the data volume corresponding to the unread data in the current preset memory are updated, so as to facilitate reading of subsequent data.
In step S103, it is determined whether or not the unreturned data amount is an integral multiple of a predetermined data amount.
In step S104, if not an integer multiple, reading data of a third data amount from the file according to the current file offset, returning the read data of the third data amount as second return data, reading data of a predetermined data amount from the file, storing the data in a preset memory, and updating the current file offset.
In the embodiment of the invention, if the unreturned data volume is not an integral multiple of the preset data volume, reading the data of the third data volume from the file according to the current file offset, returning the read data of the third data volume as the second returned data, and reading the data of the preset data volume from the file and storing the data into the preset memory, so as to update the cache data in the preset memory and facilitate the subsequent quick reading of the data from the memory. The third data volume is the product of the unreturned data volume divided by the predetermined data volume and the predetermined data volume, the updated current file offset is the sum of the file offset before updating and the third data volume, i.e., cur _ off = cur _ off + ⌊ N/T ⌋ × T, after the data of the predetermined data volume is read from the file and stored in the preset memory, the second data volume is further updated, and the updated second data volume is the predetermined data volume, i.e., P = T.
When the current file offset is updated, preferably, the current minimum file offset and the current maximum file offset are updated, so as to facilitate the file reading efficiency when the seek operation is performed in the file reading process. The current minimum file offset and the current maximum file offset correspond to an initial position and an end position of data stored in a current preset memory in a file, a difference between the current maximum file offset and the current minimum file offset is a predetermined data volume, the updated current minimum file offset is an updated current file offset, namely min _ off = cur _ off, max _ off = min _ off + T, further, the first data volume is updated, and the updated first data volume is a difference between the first data volume before updating and a third data volume, namely N = N- ⌊ N/T ⌋ × T.
As an example, if the first data volume N is 4M, the predetermined data volume is 2M, and the first returned data is 0.5M data in the preset memory, and since the unreturned data volume 3.5M after the first returned data is returned is not an integer multiple of 2M, the 2M data read from the file is returned as the second returned data, and at the same time, the 2M data read from the file is stored in the preset cache to update the cache data in the preset cache, so as to facilitate reading of subsequent files.
In step S105, data of a fourth data size is read from the preset memory and returned as third return data, and the current file offset and the second data size are updated.
In the embodiment of the present invention, the fourth data amount is the difference between the unreturned data amount described in step S103 and the third data amount, the updated second data amount is the difference between the predetermined data amount and the fourth data amount, i.e., P = P-N, and the updated current file offset is the sum of the current file offset before updating and the fourth data amount, i.e., cur _ off = cur _ off + N. In this embodiment, the sum of the first returned data, the second returned data, and the third returned data is the data amount corresponding to the data reading request, after the third returned data is returned, all the data that needs to be returned are returned, and all the data corresponding to the data reading request at this time are completely read.
As an example, if the first data volume N is 4M, the predetermined data volume is 2M, the first returned data is 0.5M data in the preset memory, the second returned data is 2M data read from the file, and the data volume of the data not read in the preset memory is 2M, the data of 1.5M is read from the preset memory and returned as the third returned data, and the file offset and the data volume corresponding to the data not read in the preset memory are updated, so as to facilitate reading of subsequent data, and the data volume corresponding to the data not read in the updated preset memory is 0.5M.
By judging whether a first data volume is smaller than a second data volume, wherein the first data volume is a data volume corresponding to a data reading request, the second data volume is a data volume corresponding to unread data in a current preset memory, if not, returning unread data in the preset memory as first return data, judging whether the unreturned data volume is integral multiple of a preset data volume, if not, reading data of a third data volume from a file, returning the read data of the third data volume as second return data, reading data of the preset data volume from the file and storing the data of the preset data volume into the preset memory, reading data of a fourth data volume from the preset memory as third return data, returning the data from the memory preferentially, and updating cache data in the memory according to the data volume corresponding to the data reading request, the reading efficiency of the file is improved.
Example two:
fig. 2 shows an implementation flow of a file reading method provided by the second embodiment of the present invention, and for convenience of description, only a part related to the second embodiment of the present invention is shown, which is detailed as follows:
in step S201, it is determined whether the first data amount is smaller than the second data amount, if so, step S202 is executed, otherwise, step S203 is executed.
In the embodiment of the present invention, the implementation of step S201 can refer to the description of step S101 in the first embodiment, and is not repeated herein.
In step S202, the data of the first data size is read from the preset memory and returned as the return data, the current file offset and the second data size are updated, and the process goes to step S208.
In the embodiment of the present invention, if the first data amount is smaller than the second data amount, that is, N < P, it indicates that the data cached in the preset memory can satisfy the data corresponding to the data reading request, at this time, the data of the first data amount is read from the unread data in the preset memory and returned as the returned data, that is, the data of N is directly read from the preset memory and returned, and the current file offset and the second data amount are updated, so as to facilitate reading of subsequent data. The updated second data amount is the difference between the second data amount before updating and the first data amount, i.e. P = P-N, and the updated current file offset is the sum of the file offset before updating and the first data amount, i.e. cur _ off = cur _ off + N. After the data of the first data amount is read from the preset memory and returned as the returned data, all the data needing to be returned are returned, and all the data corresponding to the data reading request are completely read. In this step, when the data amount in the preset memory meets the data corresponding to the data reading request, the data is directly read from the preset memory and returned, and the file does not need to be accessed, so that the efficiency of reading the file is improved.
In step S203, the unread data in the preset memory is returned as the first returned data, and the current file offset is updated.
In step S204, it is determined whether the unreturned data amount is an integral multiple of the predetermined data amount, if yes, the process jumps to step S207, otherwise, step S205 is executed.
In step S205, the data of the third data amount is read from the file according to the current file offset, the read data of the third data amount is returned as the second return data, the data of the predetermined data amount is read from the file and stored in the preset memory, and the current file offset is updated.
In step S206, data of a fourth data size is read from the preset memory and returned as third return data, the current file offset and the second data size are updated, and the process goes to step S208.
The implementation of steps S203-S206 can refer to the description of steps S102-S105 in the previous embodiment, and will not be described herein again.
In step S207, the unreturned data amount is read from the file according to the current file offset, the read unreturned data amount is returned as the second returned data, the data with the predetermined data amount is read from the file and stored in the preset memory, the current file offset and the second data amount are updated, and step S208 is executed.
In the embodiment of the present invention, the updated second data size is a predetermined data size, that is, P = T, the updated current file offset is a sum of the file offset before updating and the data size to be returned, that is, cur _ off = cur _ off + N, and when the current file offset and the second data size are updated, the current minimum file offset and the current maximum file offset are preferably updated, so as to facilitate the file reading efficiency when the seek operation is performed in the file reading process. The updated current minimum file offset is the updated current file offset, that is, min _ off = cur _ off, max _ off = min _ off + T, in this step, after the second returned data is returned, all the data that needs to be returned is returned, and all the data corresponding to the data reading request at this time is completely read.
In step S208, it is determined whether the file is completely read, if yes, step S209 is executed, otherwise, step S201 is skipped.
In step S209, it is determined that the file reading is completed.
Example three:
fig. 3 shows an implementation flow of a file reading method provided by the third embodiment of the present invention, and for convenience of description, only the parts related to the third embodiment of the present invention are shown, which are detailed as follows:
in step S301, when the seek operation is performed, it is determined whether the target location is at the current minimum file offset location or between the current minimum file offset location and the current maximum file offset location, if so, step S302 is performed, otherwise, step S303 is performed.
In the embodiment of the present invention, for convenience of description, the file offset corresponding to the target position is represented by d _ off, and if it is determined that the target position is located at the position of the current minimum file offset or located between the position of the current minimum file offset and the position of the current maximum file offset, that is, min _ off is greater than or equal to d _ off and less than max _ off, it indicates that the data corresponding to the target position is buffered in the preset memory, and the data can be directly read from the preset memory, otherwise, the data needs to be read from the file.
In step S302, the current file offset and the second data amount are updated, and the process proceeds to step S304.
In the embodiment of the present invention, if the file is from the head or the tail of the file seek to the target position, the updated second data amount is the difference between the current maximum file offset and the file offset corresponding to the target position, i.e., P = max _ off-d _ off, and the updated current file offset = the target position, i.e., cur _ off = d _ off, and if the file offset from the current position seek to the target position is expressed by offset for convenience of description, the updated second data amount is the difference between the second data amount before updating and the file offset from the current position to the target position, i.e., P = P-offset, and the updated current file offset is the sum of the file offset before updating and the file offset from the current position to the target position, i.e., cur _ off = cur _ off + offset. It should be noted here that, from the current position seek to the target position, seek is supported forward or backward from the current position to the target position, and when seek is backward, offset is positive, cur _ off increases, and P decreases, and when seek is forward, off is negative, cur _ off decreases, and P increases.
In step S303, data of a predetermined data size is read from the file according to the target position and stored in a preset memory, the current file offset, the current minimum file offset, the current maximum file offset, and the second data size are updated, and step S304 is executed.
In the embodiment of the present invention, the updated second data amount is a predetermined data amount, that is, P = T, if the file is located from the head or tail seek to the target position, the updated current file offset is the file offset corresponding to the target position, that is, cur _ off = d _ off, the updated minimum file offset is the file offset corresponding to the target position, that is, min _ off = d _ off, the updated max _ off = min _ off + T, if the file is located from the current position seek to the target position, the updated current file offset is the sum of the earlier file offset and the file offset from the current position to the target position, that is, cur _ off = cur _ off + offset, the updated min _ off = cur _ off, and the updated max _ off = min _ off + T.
In step S304, it is determined whether the first data amount is smaller than the second data amount, if so, step S305 is executed, otherwise, step S306 is skipped.
In step S305, the data of the first data size is read from the preset memory and returned as the return data, and the current file offset and the second data size are updated.
In step S306, the unread data in the preset memory is returned as the first returned data, and the current file offset is updated.
In step S307, it is determined whether the unreturned data amount is an integral multiple of the predetermined data amount, if yes, step S310 is performed, otherwise, step S308 is performed.
In step S308, the data of the third data amount is read from the file according to the current file offset, the read data of the third data amount is returned as the second return data, the data of the predetermined data amount is read from the file and stored in the preset memory, and the current file offset, the current minimum file offset, and the current maximum file offset are updated.
In step S309, data of the fourth data size is read from the preset memory and returned as the third return data, and the current file offset and the second data size are updated.
In step S310, the unreturned data amount is read from the file according to the current file offset, the read unreturned data amount is returned as the second returned data, the data with the predetermined data amount is read from the file and stored in the preset memory, and the current file offset, the current minimum file offset, the current maximum file offset, and the second data amount are updated.
The implementation of steps S304-S310 can refer to the description of steps S201-S207 in the second embodiment, which is not repeated herein, and when initially reading the file data, it is determined whether the current file offset satisfies the condition: if not, executing seek operation, and reading data with a preset data volume from the file and storing the data into the memory, and updating the minimum file offset, the maximum file offset and the second data volume, wherein the updated second data volume P = T.
In the embodiment of the invention, the file data is cached by using the memory, and when seek operation is carried out, the cached file data in the memory is updated according to the relation between the target position and the current minimum file offset and the current maximum file offset, so that the times of operating the file are reduced, the shunting speed of the audio and video file is improved, and the fluency of video playing is further improved.
Example four:
fig. 4 shows a structure of a document reading apparatus according to a fourth embodiment of the present invention, and for convenience of description, only a part related to the embodiment of the present invention is shown, where:
a data amount determining unit 41, configured to determine whether a first data amount is smaller than a second data amount, where the first data amount is a data amount corresponding to the data reading request, and the second data amount is a data amount corresponding to data that is not read in a current preset memory;
a first returning unit 42, configured to return unread data in a preset memory as first returned data if the first data size is not smaller than the second data size, and update the current file offset;
a multiple judgment unit 43 for judging whether the unreturned data amount is an integral multiple of a predetermined data amount;
a second returning unit 44, configured to, if the unreturned data amount is not an integer multiple of the predetermined data amount, read data of a third data amount from the file according to the current file offset, return the read data of the third data amount as second returned data, and store the data of the predetermined data amount read from the file in a preset memory, where the third data amount is a product of the unreturned data amount divided by the predetermined data amount and then rounded down by the predetermined data amount; and
and a third returning unit 45, configured to read data of a fourth data size from the preset memory as third returned data, and return the third returned data, and update the current file offset and the second data size, where the fourth data size is a difference between the unreturned data size and the third data size.
Preferably, the apparatus further comprises:
and the file offset updating unit is used for updating the current minimum file offset and the current maximum file offset, the current minimum file offset and the current maximum file offset correspond to the initial position and the terminal position of data stored in a preset memory in a file, and the difference between the current maximum file offset and the current minimum file offset is a preset data volume.
Preferably, the apparatus further comprises:
the position judging unit is used for judging whether the target position is positioned at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset when the seek operation is executed;
the first execution unit is used for updating the current file offset and the second data volume if the target position is located at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset; and
and the second execution unit is used for reading data with a preset data volume from the file according to the target position and storing the data into a preset memory, and updating the current file offset, the current minimum file offset, the current maximum file offset and the second data volume if the target position is not located at the position of the current minimum file offset and is not located between the position of the current minimum file offset and the position of the current maximum file offset.
In the embodiment of the present invention, each unit of the file reading apparatus may be implemented by a corresponding hardware or software unit, and each unit may be an independent software or hardware unit, or may be integrated into a software or hardware unit, which is not limited herein. The detailed description of each unit of the file reading apparatus can refer to the description of the foregoing method embodiments, and is not repeated herein.
Example five:
fig. 5 shows a structure of a file reading apparatus according to a fifth embodiment of the present invention, and for convenience of description, only a part related to the embodiment of the present invention is shown, where the structure includes:
a data amount determining unit 51, configured to determine whether a first data amount is smaller than a second data amount, where the first data amount is a data amount corresponding to the data reading request, and the second data amount is a data amount corresponding to data that is not read in a current preset memory;
a first returning unit 52, configured to return unread data in a preset memory as first returned data if the first data size is not smaller than the second data size, and update the current file offset;
a multiple judgment unit 53 for judging whether the unreturned data amount is an integral multiple of a predetermined data amount;
a second returning unit 54, configured to, if the unreturned data amount is not an integer multiple of the predetermined data amount, read data of a third data amount from the file according to the current file offset, return the read data of the third data amount as second returned data, and store the data of the predetermined data amount read from the file in a preset memory, where the third data amount is a product of the unreturned data amount divided by the predetermined data amount and then rounded down by the predetermined data amount;
a third returning unit 55, configured to read data of a fourth data size from the preset memory as a third returned data, and return the third returned data, and update the current file offset and the second data size, where the fourth data size is a difference between the unreturned data size and the third data size.
A fourth returning unit 56, configured to, if the first data size is smaller than the second data size, read data of the first data size from the preset memory as a return data, and return the return data, so as to update the current file offset and the second data size; and
a fifth returning unit 57, configured to, if the unreturned data amount is an integer multiple of the predetermined data amount, read the unreturned data amount from the file according to the current file offset, return the read unreturned data amount as the second returned data, read the predetermined data amount from the file, store the data in the preset memory, and update the current file offset and the second data amount.
In the embodiment of the present invention, each unit of the file reading apparatus may be implemented by a corresponding hardware or software unit, and each unit may be an independent software or hardware unit, or may be integrated into a software or hardware unit, which is not limited herein. The detailed description of each unit of the file reading apparatus can refer to the description of the foregoing method embodiments, and is not repeated herein.
Example six:
fig. 6 shows a structure of a computing device according to a sixth embodiment of the present invention, and for convenience of explanation, only a part related to the embodiment of the present invention is shown.
The computing device 6 of an embodiment of the present invention comprises a processor 60, a memory 61 and a computer program 62 stored in the memory 61 and executable on the processor 60. The processor 60, when executing the computer program 62, implements the steps in the above-described method embodiments, such as the steps S101 to S105 shown in fig. 1. Alternatively, the processor 60, when executing the computer program 62, implements the functions of the units in the above-described device embodiments, such as the functions of the units 41 to 45 shown in fig. 4.
In the embodiment of the present invention, by determining whether a first data volume is smaller than a second data volume, where the first data volume is a data volume corresponding to a data read request, and the second data volume is a data volume corresponding to unread data in a current preset memory, if not, returning unread data in the preset memory as first return data, determining whether the unreturned data volume is an integer multiple of a predetermined data volume, if not, reading data of a third data volume from a file, returning the read data of the third data volume as second return data, reading data of the predetermined data volume from the file and storing the data in the preset memory, reading data of a fourth data volume from the preset memory and returning the data as third return data, preferentially reading data from the memory, and updating cache data in the memory according to the data volume corresponding to the data read request, the reading efficiency of the file is improved.
Example seven:
in an embodiment of the present invention, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps in the above-described method embodiment, for example, steps S101 to S105 shown in fig. 1. Alternatively, the computer program realizes the functions of the units in the above-described device embodiments, such as the functions of the units 41 to 45 shown in fig. 4, when executed by the processor.
In the embodiment of the present invention, by determining whether a first data volume is smaller than a second data volume, where the first data volume is a data volume corresponding to a data read request, and the second data volume is a data volume corresponding to unread data in a current preset memory, if not, returning unread data in the preset memory as first return data, determining whether the unreturned data volume is an integer multiple of a predetermined data volume, if not, reading data of a third data volume from a file, returning the read data of the third data volume as second return data, reading data of the predetermined data volume from the file and storing the data in the preset memory, reading data of a fourth data volume from the preset memory and returning the data as third return data, preferentially reading data from the memory, and updating cache data in the memory according to the data volume corresponding to the data read request, the reading efficiency of the file is improved.
The computer readable storage medium of the embodiments of the present invention may include any entity or device capable of carrying computer program code, a recording medium, such as a ROM/RAM, a magnetic disk, an optical disk, a flash memory, or the like.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.

Claims (6)

1. A method for reading a document, the method comprising the steps of:
judging whether a first data volume is smaller than a second data volume, wherein the first data volume is a data volume corresponding to a data reading request, and the second data volume is a data volume corresponding to unread data in a current preset memory;
if not, returning the unread data in the preset memory as first return data, and updating the current file offset;
judging whether the unreturned data volume is integral multiple of the preset data volume or not;
if the difference is not an integral multiple, reading data of a third data volume from an audio and video file according to the current file offset, returning the read data of the third data volume as second return data, reading data of the preset data volume from the audio and video file, storing the data of the preset data volume into the preset memory, updating the current file offset, and updating the current minimum file offset and the current maximum file offset, wherein the third data volume is the product of the unreturned data volume divided by the preset data volume and then rounded down, the current minimum file offset and the current maximum file offset correspond to the initial position and the final position of the data stored in the preset memory in the audio and video file, and the difference between the current maximum file offset and the current minimum file offset is the preset data volume;
reading data of a fourth data volume from the preset memory as third return data to be returned, and updating the current file offset and the second data volume, wherein the fourth data volume is the difference between the unreturned data volume and the third data volume;
the method further comprises the following steps:
when the seek operation is executed, judging whether the target position is at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset;
if so, updating the current file offset and the second data volume;
and if not, reading the data with the preset data volume from the audio and video file according to the target position, storing the data into the preset memory, and updating the current file offset, the current minimum file offset, the current maximum file offset and the second data volume.
2. The method of claim 1, wherein the step of determining whether the first amount of data is less than the second amount of data is followed by:
if the current file offset is smaller than the second data volume, reading the data of the first data volume from the preset memory as return data, and updating the current file offset and the second data volume;
after the step of judging whether the unreturned data volume is an integral multiple of the predetermined data volume, the method comprises the following steps:
and if the number of the data is integral multiple, reading the data of the unreturned data volume from the audio and video file according to the current file offset, returning the read data of the unreturned data volume as second returned data, reading the data of the preset data volume from the audio and video file, storing the data of the preset data volume into the preset memory, and updating the current file offset and the second data volume.
3. A document reading apparatus, characterized in that the apparatus comprises:
the data volume judging unit is used for judging whether a first data volume is smaller than a second data volume, wherein the first data volume is a data volume corresponding to a data reading request, and the second data volume is a data volume corresponding to unread data in a current preset memory;
a first returning unit, configured to return, if the first data amount is not smaller than the second data amount, the unread data in the preset memory as first returned data, and update the current file offset;
a multiple judgment unit for judging whether the unreturned data amount is an integral multiple of the predetermined data amount;
a second returning unit, configured to, if the unreturned data amount is not an integral multiple of the predetermined data amount, read data of a third data amount from the audio/video file according to the current file offset, return the read data of the third data amount as second returned data, read data of the predetermined data amount from the audio/video file, store the data in the predetermined data amount in the preset memory, and update the current file offset, where the third data amount is a product of the unreturned data amount divided by the predetermined data amount and then rounded down by the predetermined data amount; and
a third returning unit, configured to read data of a fourth data size from the preset memory as third returned data, return the third returned data, and update the current file offset and the second data size, where the fourth data size is a difference between the unreturned data size and the third data size;
the device further comprises:
the file offset updating unit is used for updating the current minimum file offset and the current maximum file offset, the current minimum file offset and the current maximum file offset correspond to the initial position and the final position of the data stored in the preset memory in the audio/video file, and the difference between the current maximum file offset and the current minimum file offset is the preset data volume;
the position judging unit is used for judging whether the target position is positioned at the position of the current minimum file offset or between the position of the current minimum file offset and the position of the current maximum file offset when the seek operation is executed;
a first execution unit, configured to update the current file offset and the second data size if the target location is located at a current minimum file offset location or between the current minimum file offset location and a current maximum file offset location; and
and the second execution unit is used for reading the data with the preset data volume from the audio and video file according to the target position and storing the data into the preset memory, and updating the current file offset, the current minimum file offset, the current maximum file offset and the second data volume if the target position is not located at the position of the current minimum file offset and is not located between the position of the current minimum file offset and the position of the current maximum file offset.
4. The apparatus of claim 3, wherein the apparatus further comprises:
a fourth returning unit, configured to, if the first data size is smaller than the second data size, read data of the first data size from the preset memory as a return data, and return the return data, so as to update the current file offset and the second data size; and
and the fifth returning unit is used for reading the data of the unreturned data volume from the audio and video file according to the current file offset if the unreturned data volume is an integral multiple of the preset data volume, returning the read data of the unreturned data volume as second returned data, reading the data of the preset data volume from the audio and video file, storing the data of the preset data volume into the preset memory, and updating the current file offset and the second data volume.
5. A computing device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1 to 2 when executing the computer program.
6. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 2.
CN201911401308.6A 2019-12-31 2019-12-31 File reading method and device, computing equipment and storage medium Active CN110784756B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911401308.6A CN110784756B (en) 2019-12-31 2019-12-31 File reading method and device, computing equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911401308.6A CN110784756B (en) 2019-12-31 2019-12-31 File reading method and device, computing equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110784756A CN110784756A (en) 2020-02-11
CN110784756B true CN110784756B (en) 2020-05-29

Family

ID=69394724

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911401308.6A Active CN110784756B (en) 2019-12-31 2019-12-31 File reading method and device, computing equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110784756B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1607498A (en) * 2003-10-13 2005-04-20 英业达股份有限公司 Method for accessing file data in application program
CN101556541A (en) * 2009-05-14 2009-10-14 北京握奇数据系统有限公司 Method for manufacturing intelligent card, device, master card and system
CN102547435A (en) * 2011-12-16 2012-07-04 Tcl集团股份有限公司 System and method for playing and processing multimedia file
CN103077225A (en) * 2012-12-31 2013-05-01 华为技术有限公司 Data reading method, device and system
CN103116618A (en) * 2013-01-28 2013-05-22 南开大学 Telefile system mirror image method and system based on lasting caching of client-side
CN103608785A (en) * 2013-06-21 2014-02-26 华为技术有限公司 Method for reading file, storage device and reading system
CN103716573A (en) * 2013-12-13 2014-04-09 乐视致新电子科技(天津)有限公司 Video playback method and device
CN105487811A (en) * 2015-02-09 2016-04-13 哈尔滨安天科技股份有限公司 File reading and writing method and system based on buffering alignment
WO2018054200A1 (en) * 2016-09-26 2018-03-29 上海泓智信息科技有限公司 Method and device for reading file

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9489456B1 (en) * 2006-11-17 2016-11-08 Blue Coat Systems, Inc. Previewing file information over a network
CN108021333B (en) * 2016-11-03 2021-08-24 阿里巴巴集团控股有限公司 System, device and method for randomly reading and writing data
CN107273310A (en) * 2017-06-30 2017-10-20 浙江大华技术股份有限公司 A kind of read method of multi-medium data, device, medium and equipment

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1607498A (en) * 2003-10-13 2005-04-20 英业达股份有限公司 Method for accessing file data in application program
CN101556541A (en) * 2009-05-14 2009-10-14 北京握奇数据系统有限公司 Method for manufacturing intelligent card, device, master card and system
CN102547435A (en) * 2011-12-16 2012-07-04 Tcl集团股份有限公司 System and method for playing and processing multimedia file
CN103077225A (en) * 2012-12-31 2013-05-01 华为技术有限公司 Data reading method, device and system
CN103116618A (en) * 2013-01-28 2013-05-22 南开大学 Telefile system mirror image method and system based on lasting caching of client-side
CN103608785A (en) * 2013-06-21 2014-02-26 华为技术有限公司 Method for reading file, storage device and reading system
CN103716573A (en) * 2013-12-13 2014-04-09 乐视致新电子科技(天津)有限公司 Video playback method and device
CN105487811A (en) * 2015-02-09 2016-04-13 哈尔滨安天科技股份有限公司 File reading and writing method and system based on buffering alignment
WO2018054200A1 (en) * 2016-09-26 2018-03-29 上海泓智信息科技有限公司 Method and device for reading file

Also Published As

Publication number Publication date
CN110784756A (en) 2020-02-11

Similar Documents

Publication Publication Date Title
US8412893B2 (en) Data storage device and method for handling data read out from memory using a ping-pong buffer
US10133679B2 (en) Read cache management method and apparatus based on solid state drive
US8504736B2 (en) File input/output scheduler
CN110147204B (en) Metadata disk-dropping method, device and system and computer-readable storage medium
WO2017185616A1 (en) File storage method and electronic equipment
CN110764708A (en) Data reading method, device, equipment and storage medium
CN108874688B (en) Message data caching method and device
CN107801095B (en) audio and video decoding method and terminal equipment
CN107480074B (en) Caching method and device and electronic equipment
US20170308546A1 (en) File storage method and electronic device
US20210271640A1 (en) File loading method and apparatus, electronic device, and storage medium
CN109271253A (en) A kind of resource allocation method, apparatus and system
CN105142004A (en) Multi-media file reading method and multi-media file reading device
CN109558456A (en) A kind of file migration method, apparatus, equipment and readable storage medium storing program for executing
CN106569963A (en) Buffering method and buffering device
CN111625515A (en) Method and device for processing operation request of aggregated small files
CN108334383B (en) Information processing method and electronic equipment
KR20150035876A (en) Method for de-duplicating data and apparatus therefor
CN110784756B (en) File reading method and device, computing equipment and storage medium
US10270683B2 (en) Communication method, communication device, and recording medium for streaming
CN111061429B (en) Data access method, device, equipment and medium
CN111159124B (en) Asynchronous write caching method, device and medium for Linux kernel file system
CN114238161A (en) Intelligent disk fragment sorting method and device and electronic equipment
US9761030B2 (en) Scene image generator
CN113986849A (en) Music caching method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant