2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_MEM_FILE_H_
18 #define incl_HPHP_MEM_FILE_H_
20 #include "hphp/runtime/base/file.h"
21 #include "hphp/runtime/base/type-array.h"
22 #include "hphp/runtime/base/type-string.h"
25 ///////////////////////////////////////////////////////////////////////////////
30 struct MemFile
: File
{
31 DECLARE_RESOURCE_ALLOCATION(MemFile
);
33 explicit MemFile(const String
& wrapper_type
= null_string
,
34 const String
& stream_type
= empty_string_ref
);
35 MemFile(const char *data
, int64_t len
,
36 const String
& wrapper_type
= null_string
,
37 const String
& stream_type
= empty_string_ref
);
40 CLASSNAME_IS("MemFile");
41 // overriding ResourceData
42 const String
& o_getClassNameHook() const override
{ return classnameof(); }
44 bool open(const String
& filename
, const String
& mode
) override
;
45 bool close() override
;
46 int64_t readImpl(char *buffer
, int64_t length
) override
;
48 int64_t writeImpl(const char *buffer
, int64_t length
) override
;
49 bool seekable() override
{ return true;}
50 bool seek(int64_t offset
, int whence
= SEEK_SET
) override
;
51 int64_t tell() override
;
53 bool rewind() override
;
54 bool flush() override
;
56 Array
getMetaData() override
;
61 char *m_data
; // data of the memory file
62 int64_t m_len
; // length of the memory file
63 int64_t m_cursor
; // m_data's read position
64 bool m_malloced
; // whether to free m_data on delete
69 ///////////////////////////////////////////////////////////////////////////////
72 #endif // incl_HPHP_MEM_FILE_H_