private function insertChunksFromFile($handle, $record, &$md5)
    {
        $written = 0;
        $offset = 0;
        $i = 0;

        $fileId = $record['_id'];
        $chunkSize = $record['chunkSize'];

        $hash = hash_init('md5');

        rewind($handle);
        while (! feof($handle)) {
            $data = stream_get_contents($handle, $chunkSize);
            hash_update($hash, $data);
            $this->insertChunk($fileId, $data, $i++);
            $written += strlen($data);
            $offset += $chunkSize;
        }

        $md5 = hash_final($hash);

        return $written;
    }