SnapchatAgent::unCompress PHP Method

unCompress() public method

Array( overlay~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0 => overlay_file_data, media~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0 => m4v_file_data )
public unCompress ( data $data ) : array
$data data The blob data (or just the header).
return array Array containing both file contents, or FALSE if couldn't extract.
    function unCompress($data)
    {
        if (!file_put_contents("./temp", $data)) {
            exit('Should have write access to own folder');
        }
        $resource = zip_open("./temp");
        $result = FALSE;
        if (is_resource($resource)) {
            while ($zip_entry = zip_read($resource)) {
                $filename = zip_entry_name($zip_entry);
                if (zip_entry_open($resource, $zip_entry, "r")) {
                    $result[$filename] = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                    zip_entry_close($zip_entry);
                } else {
                    return FALSE;
                }
            }
            zip_close($resource);
        }
        return $result;
    }

Usage Example

コード例 #1
0
ファイル: snapchat.php プロジェクト: nodir-y/SC-API
 /**
  * Downloads a story.
  *
  * @param string $media_id
  *   The media ID of the story.
  * @param string $key
  *   The base64-encoded key of the story.
  * @param string $iv
  *   The base64-encoded IV of the story.
  *
  * @return mixed
  *   The story data or FALSE on failure.
  */
 public function getStory($media_id, $key, $iv, $from, $timestamp, $save = FALSE, $subdir = null)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     // Build path
     if ($save) {
         if ($subdir == null) {
             $subdir = $this->username;
         }
         $path = __DIR__ . DIRECTORY_SEPARATOR . "stories" . DIRECTORY_SEPARATOR . $subdir . DIRECTORY_SEPARATOR . $from;
         if (!file_exists($path)) {
             mkdir($path, 0777, true);
         }
         $file = $path . DIRECTORY_SEPARATOR . date("Y-m-d H-i-s", (int) ($timestamp / 1000)) . "-story-" . $media_id;
         $extensions = array(".jpg", ".png", ".mp4", "");
         foreach ($extensions as $ext) {
             if (file_exists($file . $ext)) {
                 return false;
             }
         }
     }
     // Retrieve encrypted story and decrypt.
     $blob = parent::get('/bq/story_blob?story_id=' . $media_id);
     if (!empty($blob)) {
         $result = parent::decryptCBC($blob, $key, $iv);
         if (parent::isCompressed(substr($result, 0, 2))) {
             $result = parent::unCompress($result);
         }
         if ($save) {
             if (is_array($result)) {
                 foreach ($result as &$value) {
                     if (!file_exists($file)) {
                         $this->writeToFile($file, $value);
                     }
                 }
             } else {
                 if (!file_exists($file)) {
                     $this->writeToFile($file, $result);
                 }
             }
         }
         return $result;
     }
     return FALSE;
 }
All Usage Examples Of SnapchatAgent::unCompress