private function openFile($file, $mode)
    {
        $handle = @fopen($file, $mode);
        if ($handle === false) {
            throw new \InvalidArgumentException("Could not open $file");
        }
        return $handle;
    }