OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_BASE_FILE_H_ | |
12 #define WEBRTC_BASE_FILE_H_ | |
13 | |
14 #include <stdint.h> | |
15 | |
16 #include "webrtc/base/platform_file.h" | |
17 #include "webrtc/base/constructormagic.h" | |
18 | |
19 namespace rtc { | |
20 | |
21 // This class wraps the platform specific APIs for simple file interactions. | |
22 // | |
23 // The regular read and write methods (Write|Read)(At)? are best effort, i.e. | |
24 // if an underlying call does not manage to read/write all the data more calls | |
25 // will be performed, until an error is detected or all data is read/written. | |
26 // The NoBestEffort variants do not do this. | |
sprang_webrtc
2016/08/15 09:43:07
I'm thinking we should switch this naming around,
palmkvist
2016/08/16 08:55:35
I agree that WriteAll should be the default, but I
sprang
2016/08/16 09:27:44
Agreed, let's only add a best-effort method if we
| |
27 class File { | |
28 public: | |
29 // Wraps the given PlatformFile. This class is then responsible for closing | |
30 // the file, which will be done in the destructor if Close is never called. | |
31 explicit File(PlatformFile); | |
32 ~File(); | |
33 | |
34 size_t Write(const uint8_t* data, size_t length); | |
35 size_t Read(uint8_t* buffer, size_t length); | |
36 | |
37 size_t WriteAt(const uint8_t* data, size_t length, size_t offset); | |
38 size_t ReadAt(uint8_t* buffer, size_t length, size_t offset); | |
39 | |
40 size_t WriteNoBestEffort(const uint8_t* data, size_t length); | |
41 size_t ReadNoBestEffort(uint8_t* buffer, size_t length); | |
42 | |
43 size_t WriteAtNoBestEffort(const uint8_t* data, size_t length, size_t offset); | |
44 size_t ReadAtNoBestEffort(uint8_t* buffer, size_t length, size_t offset); | |
45 | |
46 // Attempt to position the file at the given offset from the start. | |
47 // Returns true if successful, false otherwise. | |
48 bool Seek(size_t offset); | |
49 | |
50 // Attempt to close the file. Returns true if successful, false otherwise, | |
51 // most notably when the file is already closed. | |
52 bool Close(); | |
53 | |
54 private: | |
55 rtc::PlatformFile file_; | |
56 RTC_DISALLOW_COPY_AND_ASSIGN(File); | |
57 }; | |
58 | |
59 } // namespace rtc | |
60 | |
61 #endif // WEBRTC_BASE_FILE_H_ | |
OLD | NEW |