/** * @see \qtism\runtime\storage\binary\AbstractQtiBinaryStreamAccess::writeFile() */ public function writeFile(QtiFile $file) { try { $this->writeString($file->getPath()); } catch (QtiBinaryStreamAccessException $e) { $msg = "An error occured while reading a QTI File."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e); } }
/** * Delete a FileSystemFile object from the persistence. * * @throws \qtism\common\datatypes\files\FileManagerException */ public function delete(QtiFile $file) { $deletion = @unlink($file->getPath()); if ($deletion === false) { $msg = "The File System File located at '" . $file->getPath() . "' could not be deleted gracefully."; throw new FileManagerException($msg); } }
/** * Marshall a QTI File datatype into a binary string. The resulting binary string constitution * is the following: * * * The length of the file name, unsigned short. * * The file name, string. * * The length of the mime type, unsigned short. * * The mime type, string. * * The binary content of the file, string. * * @param File $file * @return string */ public static function qtiFileToString(QtiFile $file) { $string = ''; $filename = $file->getFilename(); $mimetype = $file->getMimeType(); $filenameLen = strlen($filename); $mimetypeLen = strlen($mimetype); $string .= pack('S', $filenameLen); $string .= $filename; $string .= pack('S', $mimetypeLen); $string .= $mimetype; // Avoid invalid data for serialize // (This could make me cry...) $string .= $file->getData(); return $string; }
/** * Marshall a QTI file datatype into its PCI JSON Representation. * * @param \qtism\common\datatypes\File $file * @return array */ protected function marshallFile(QtiFile $file) { $data = array('base' => array('file' => array('mime' => $file->getMimeType(), 'data' => base64_encode($file->getData())))); if ($file->hasFilename() === true) { $data['base']['file']['name'] = $file->getFilename(); } return $data; }