writer = $writer; } public function saveFile($file) { $isSymlink = false; //currently not used foreach ($this->files as $f) { if ($f->name() == $file->name()) { return false; } if ($f->sha256() == $file->sha256()) { $isSymlink = true; } } $file->setOffset($this->writer->offset()); $this->writer->write($file->readLocalFileHeader()); while (($buffer = $file->readFileData()) !== null) { $this->writer->write($buffer); } $this->writer->write($file->readDataDescriptor()); $this->files[] = $file; $file->closeHandle(); return true; } public function close() { $size = 0; $offset = $this->writer->offset(); foreach ($this->files as $file) { $size += $this->writer->write($file->readCentralDirectoryHeader()); } $data = ""; $data .= "\x50\x4b\x05\x06"; $data .= "\x00\x00"; //number of disks $data .= "\x00\x00"; //number of the disk with the start of the central directory $data .= pack("v", count($this->files)); //total number of entries in the central directory on this disk $data .= pack("v", count($this->files)); //total number of entries in the central directory $data .= pack("V", $size); //size of the central directory $data .= pack("V", $offset); //offset of start of central directory with respect to the starting disk number $data .= "\x0\x0"; //comment length $this->writer->write($data); } } }