Skip to content

Commit 087194a

Browse files
committed
cache fs:*.zip?/ file data.
1 parent 378e527 commit 087194a

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

fibjs/src/fs/fs.cpp

+35-43
Original file line numberDiff line numberDiff line change
@@ -90,63 +90,55 @@ result_t fs_base::open(exlib::string fname, exlib::string flags,
9090
list = it->second;
9191
s_cachelock.unlock();
9292

93-
if (list) {
94-
int32_t len, i;
95-
bool bFound = false;
93+
if (list == NULL) {
94+
hr = zip_base::cc_open(zip_file, "r", zip_base::_ZIP_DEFLATED, zfile);
95+
if (hr < 0)
96+
return hr;
9697

97-
list->get_length(len);
98+
hr = zfile->cc_readAll("", list);
99+
if (hr < 0)
100+
return hr;
98101

99-
for (i = 0; i < len; i++) {
100-
Variant v;
101-
exlib::string s;
102+
s_cachelock.lock();
103+
s_cache.insert(std::pair<exlib::string, obj_ptr<List_base> >(zip_file, list));
104+
s_cachelock.unlock();
105+
}
102106

103-
list->_indexed_getter(i, v);
104-
s = v.string();
107+
int32_t len, i;
108+
bool bFound = false;
109+
obj_ptr<ZipInfo_base> zi;
105110

106-
if (member == s) {
107-
bFound = true;
108-
break;
109-
}
111+
list->get_length(len);
110112

111-
#ifdef _WIN32
112-
if (bChanged && member1 == s) {
113-
member = member1;
114-
bFound = true;
115-
break;
116-
}
117-
#endif
118-
}
113+
for (i = 0; i < len; i++) {
114+
Variant v;
115+
exlib::string s;
119116

120-
if (!bFound)
121-
return CALL_E_FILE_NOT_FOUND;
122-
}
117+
list->_indexed_getter(i, v);
118+
zi = ZipInfo_base::getInstance(v.object());
123119

124-
hr = zip_base::cc_open(zip_file, "r", zip_base::_ZIP_DEFLATED, zfile);
125-
if (hr < 0)
126-
return hr;
120+
zi->get_filename(s);
127121

128-
if (list == NULL) {
129-
zfile->cc_namelist(list);
130-
s_cache.insert(std::pair<exlib::string, obj_ptr<List_base> >(zip_file, list));
131-
}
122+
if (member == s) {
123+
bFound = true;
124+
break;
125+
}
132126

133-
hr = zfile->cc_read(member, "", data);
134-
if (hr < 0) {
135-
hr = CALL_E_FILE_NOT_FOUND;
136127
#ifdef _WIN32
137-
if (bChanged) {
138-
hr = zfile->cc_read(member1, "", data);
139-
if (hr < 0)
140-
return hr;
141-
} else
142-
return hr;
143-
#else
144-
return hr;
128+
if (bChanged && member1 == s) {
129+
member = member1;
130+
bFound = true;
131+
break;
132+
}
145133
#endif
146134
}
147135

148-
data->toString(strData);
136+
if (!bFound)
137+
return CALL_E_FILE_NOT_FOUND;
149138

139+
zi->get_data(data);
140+
if (data)
141+
data->toString(strData);
150142
retVal = new MemoryStream::CloneStream(strData, s_date);
151143
} else {
152144
obj_ptr<File> pFile = new File();

0 commit comments

Comments
 (0)