1 28 29 package com.caucho.quercus.lib.zip; 30 31 import com.caucho.quercus.QuercusModuleException; 32 import com.caucho.quercus.annotation.NotNull; 33 import com.caucho.quercus.annotation.Optional; 34 import com.caucho.quercus.annotation.ReturnNullAsFalse; 35 import com.caucho.quercus.env.BooleanValue; 36 import com.caucho.quercus.env.Env; 37 import com.caucho.quercus.env.LongValue; 38 import com.caucho.quercus.env.StringValueImpl; 39 import com.caucho.quercus.env.Value; 40 import com.caucho.quercus.lib.file.BinaryInput; 41 import com.caucho.quercus.lib.file.BinaryStream; 42 import com.caucho.quercus.lib.file.FileModule; 43 import com.caucho.quercus.module.AbstractQuercusModule; 44 import com.caucho.util.L10N; 45 46 import java.io.IOException ; 47 import java.util.logging.Level ; 48 import java.util.logging.Logger ; 49 50 53 public class ZipModule extends AbstractQuercusModule { 54 private static final Logger log = 55 Logger.getLogger(ZipModule.class.getName()); 56 private static final L10N L = new L10N(ZipModule.class); 57 58 public String []getLoadedExtensions() 59 { 60 return new String [] { "zip" }; 61 } 62 63 67 @ReturnNullAsFalse 68 public ZipDirectory zip_open(Env env, 69 String filename) 70 { 71 if (filename == null || filename == "") 72 return null; 73 74 BinaryStream s = FileModule.fopen(env, filename, "rb", false, null); 75 76 if (s == null) 77 return null; 78 79 return new ZipDirectory((BinaryInput)s); 80 } 81 82 86 @ReturnNullAsFalse 87 public QuercusZipEntry zip_read(Env env, 88 @NotNull ZipDirectory directory) 89 { 90 try { 91 if (directory == null) 92 return null; 93 94 QuercusZipEntry qze = directory.zip_read(); 95 zip_entry_open(env, directory, qze, "rb"); 96 97 return qze; 98 99 } catch (IOException e) { 100 throw new QuercusModuleException(e); 101 } 102 } 103 104 111 public Value zip_entry_name(Env env, 112 @NotNull QuercusZipEntry entry) 113 { 114 if (entry == null) 115 return BooleanValue.FALSE; 116 117 return new StringValueImpl(entry.zip_entry_name()); 118 } 119 120 126 public Value zip_entry_filesize(@NotNull QuercusZipEntry entry) 127 { 128 if (entry == null) 129 return BooleanValue.FALSE; 130 131 return new LongValue(entry.zip_entry_filesize()); 132 } 133 134 137 public boolean zip_close(@NotNull ZipDirectory directory) 138 { 139 if (directory == null) 140 return false; 141 return directory.zip_close(); 142 } 143 144 152 public boolean zip_entry_open(Env env, 153 @NotNull ZipDirectory directory, 154 @NotNull QuercusZipEntry entry, 155 @Optional String mode) 156 { 157 if ((directory == null) || (entry == null)) 158 return false; 159 160 return entry.zip_entry_open(env, directory); 161 } 162 163 169 public boolean zip_entry_close(Env env, 170 @NotNull QuercusZipEntry entry) 171 { 172 try { 173 if (entry == null) 174 return false; 175 return entry.zip_entry_close(); 176 177 } catch (IOException e) { 178 env.warning(L.l(e.toString())); 179 log.log(Level.FINE, e.toString(), e); 180 return false; 181 } 182 } 183 184 191 public Value zip_entry_read(Env env, 192 @NotNull QuercusZipEntry entry, 193 @Optional("1024") int length) 194 { 195 if (entry == null) 196 return BooleanValue.FALSE; 197 198 return entry.zip_entry_read(env, length); 199 } 200 201 208 public String zip_entry_compressionmethod(@NotNull QuercusZipEntry entry) 209 { 210 if (entry == null) 211 return ""; 212 213 return entry.zip_entry_compressionmethod(); 214 } 215 216 222 public Value zip_entry_compressedsize(@NotNull QuercusZipEntry entry) 223 { 224 if (entry == null) 225 return new LongValue(-1); 226 227 return entry.zip_entry_compressedsize(); 228 } 229 } 230 | Popular Tags |