FileStream.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2010 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  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
  13. * distribution.
  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.
  17. *
  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.
  29. */
  30. #ifndef FileStream_h
  31. #define FileStream_h
  32. #if ENABLE(BLOB)
  33. #include "FileSystem.h"
  34. #include <wtf/Forward.h>
  35. #include <wtf/PassRefPtr.h>
  36. #include <wtf/RefCounted.h>
  37. namespace WebCore {
  38. class KURL;
  39. // All methods are synchronous.
  40. class FileStream : public RefCounted<FileStream> {
  41. public:
  42. static PassRefPtr<FileStream> create()
  43. {
  44. return adoptRef(new FileStream());
  45. }
  46. ~FileStream();
  47. // FIXME: To be removed when we switch to using BlobData.
  48. void start();
  49. // Aborts the operation.
  50. void stop();
  51. // 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.
  52. // Returns total number of bytes if successful. -1 otherwise.
  53. long long getSize(const String& path, double expectedModificationTime);
  54. // Opens a file for reading. The reading starts at the specified offset and lasts till the specified length.
  55. // Returns true on success. False otherwise.
  56. bool openForRead(const String& path, long long offset, long long length);
  57. // Opens a file for writing.
  58. // Returns true on success. False otherwise.
  59. bool openForWrite(const String& path);
  60. // Closes the file.
  61. void close();
  62. // Reads a file into the provided data buffer.
  63. // Returns number of bytes being read on success. -1 otherwise.
  64. // If 0 is returned, it means that the reading is completed.
  65. int read(char* buffer, int length);
  66. // Writes a blob to the file.
  67. // Returns number of bytes being written on success. -1 otherwise.
  68. int write(const KURL& blobURL, long long position, int length);
  69. // Truncates the file to the specified position.
  70. // Returns true on success. False otherwise.
  71. bool truncate(long long position);
  72. private:
  73. FileStream();
  74. PlatformFileHandle m_handle;
  75. long long m_bytesProcessed;
  76. long long m_totalBytesToRead;
  77. };
  78. } // namespace WebCore
  79. #endif // ENABLE(BLOB)
  80. #endif // FileStream_h