SnapchatAgent::isCompressed PHP Method

isCompressed() public method

Checks to see if a blob looks like a compressed file.
public isCompressed ( data $data ) : boolean
$data data The blob data (or just the header).
return boolean TRUE if the blob looks like a compressed file, FALSE otherwise.
    function isCompressed($data)
    {
        // Check for a PK header.
        if ($data[0] == chr(0x50) && $data[1] == chr(0x4b)) {
            return TRUE;
        }
        return FALSE;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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::isCompressed