2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
36 #include "FileSystem.h"
37 #include <wtf/Forward.h>
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/RefCounted.h>
45 // All methods are synchronous.
46 class FileStream : public RefCounted<FileStream> {
48 static PassRefPtr<FileStream> create()
50 return adoptRef(new FileStream());
54 // FIXME: To be removed when we switch to using BlobData.
57 // Aborts the operation.
60 // Gets the size of a file. Also validates if the file has been changed or not if the expected modification time is provided, i.e. non-zero.
61 // Returns total number of bytes if successful. -1 otherwise.
62 long long getSize(const String& path, double expectedModificationTime);
64 // Opens a file for reading. The reading starts at the specified offset and lasts till the specified length.
65 // Returns true on success. False otherwise.
66 bool openForRead(const String& path, long long offset, long long length);
68 // Opens a file for writing.
69 // Returns true on success. False otherwise.
70 bool openForWrite(const String& path);
75 // Reads a file into the provided data buffer.
76 // Returns number of bytes being read on success. -1 otherwise.
77 // If 0 is returned, it means that the reading is completed.
78 int read(char* buffer, int length);
80 // Writes a blob to the file.
81 // Returns number of bytes being written on success. -1 otherwise.
82 int write(const KURL& blobURL, long long position, int length);
84 // Truncates the file to the specified position.
85 // Returns true on success. False otherwise.
86 bool truncate(long long position);
91 PlatformFileHandle m_handle;
92 long long m_bytesProcessed;
93 long long m_totalBytesToRead;
96 } // namespace WebCore
98 #endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
100 #endif // FileStream_h