Push a chunk of a file to the streaming endpoint.

        Args:
            filename: Name of file that this is a chunk of.
            chunk_id: TODO: change to 'offset'
            chunk: File data.
356398
def push(self, filename, data):
        
        self._queue.put(Chunk(filename, data))
1194686
def _download_chunk(self, chunk_offset, chunk_size):
        """"""
        range_id = 'bytes={0}-{1}'.format(
            chunk_offset, chunk_offset + chunk_size - 1)

        return self._blob_service.get_blob(
            container_name=self._container_name,
            blob_name=self._blob_name,
            x_ms_range=range_id)
465907
def _append_filename_extension(self, response: BaseResponse):
        ''''''
        if not self._filename:
            return

        if response.request.url_info.scheme not in ('http', 'https'):
            return

        if not re.search(r'\.[hH][tT][mM][lL]?$', self._filename) and \
                HTMLReader.is_response(response):
            self._filename += '.html'
        elif not re.search(r'\.[cC][sS][sS]$', self._filename) and \
                CSSReader.is_response(response):
            self._filename += '.css'
1150932
def get_starting_chunk(filename, length=1024):
    
    # Ensure we open the file in binary mode
    with open(filename, 'rb') as f:
        chunk = f.read(length)
        return chunk
658280
def load (self, filename):
        
        if self.filename is None:
            self.filename = filename

        stream = open(self.filename, "rb")
        for doc in yaml.load_all(stream):
            for table in doc:
                self.add(table)
        stream.close()
816697
def upload_simple(filename, overwrite:, target_name:)
      target_file = get(target_name)
      exist = target_file.file?
      return if exist && !overwrite
      path = nil
      if exist
        path = "#{target_file.api_path}/content"
      else
        path = "#{api_path}:/#{target_name}:/content"
      end

      query = {
        path: File.join('v1.0/me/', path),
        headers: {
          'Authorization': "Bearer #{@od.access_token.token}",
          'Content-Type': 'application/octet-stream'
        },
        body: File.read(filename)
      }
      result = @od.conn.put(query)
      result = JSON.parse(result.body)
      file = OneDriveFile.new(@od, result)
      file.set_mtime(File.mtime(filename))
    end
92415
def load(cls, filename):
        
        cls.load_counter_offset = StoreOptions.id_offset()
        val = pickle.load(filename)
        cls.load_counter_offset = None
        return val
1032457
def save(self, name, file):
        
        # Get the proper name for the file, as it will actually be saved.
        if name is None:
            name = file.name

        if not hasattr(file, 'chunks'):
            file = File(file, name=name)

        name = self.get_available_name(name)
        name = self._save(name, file)

        # Store filenames with forward slashes, even on Windows
        return name.replace('\\', '/')
6814
function push (chunk) {
		if (!isAudioBuffer(chunk)) {
			chunk = util.create(chunk, channels)
		}

		data.append(chunk)

		isEmpty = false;
	}
297060
def add_file(self, filename, overwrite=False):
        

        with open(filename, 'r') as fin:
            self.add(fin.read(), overwrite)
1206019
def __flush_data(self, data):
        
        # Ensure the index, even if there's nothing to write, so
        # the filemd5 command always succeeds.
        self.__ensure_indexes()
        self._file['md5'].update(data)

        if not data:
            return
        assert(len(data) <= self.chunk_size)

        chunk = {"files_id": self._file["_id"],
                 "n": self._chunk_number,
                 "data": Binary(data)}

        try:
            self._chunks.insert_one(chunk)
        except DuplicateKeyError:
            self._raise_file_exists(self._file['_id'])
        self._chunk_number += 1
        self._position += len(data)
104706
def upload_file(token, channel_name, file_name):
    

    slack = Slacker(token)

    slack.files.upload(file_name, channels=channel_name)
333272
def put_file(self, filename, index, doc_type, id=None, name=None):
        
        if id is None:
            request_method = 'POST'
        else:
            request_method = 'PUT'
        path = make_path(index, doc_type, id)
        doc = file_to_attachment(filename)
        if name:
            doc["_name"] = name
        return self._send_request(request_method, path, doc)
705112
def get_starting_chunk(filename, length=1024):
    
    # Ensure we open the file in binary mode
    try:
        with open(filename, 'rb') as f:
            chunk = f.read(length)
            return chunk
    except IOError as e:
        print(e)
365761
def upload_chunked(self, filename, *args, **kwargs):
        
        f = kwargs.pop('file', None)

        # Media category is dependant on whether media is attached to a tweet
        # or to a direct message. Assume tweet by default.
        is_direct_message = kwargs.pop('is_direct_message', False)

        # Initialize upload (Twitter cannot handle videos > 15 MB)
        headers, post_data, fp = API._chunk_media('init', filename, self.max_size_chunked, form_field='media', f=f, is_direct_message=is_direct_message)
        kwargs.update({'headers': headers, 'post_data': post_data})

        # Send the INIT request
        media_info = bind_api(
            api=self,
            path='/media/upload.json',
            method='POST',
            payload_type='media',
            allowed_param=[],
            require_auth=True,
            upload_api=True
        )(*args, **kwargs)

        # If a media ID has been generated, we can send the file
        if media_info.media_id:
            # default chunk size is 1MB, can be overridden with keyword argument.
            # minimum chunk size is 16K, which keeps the maximum number of chunks under 999
            chunk_size = kwargs.pop('chunk_size', 1024 * 1024)
            chunk_size = max(chunk_size, 16 * 2014)

            fsize = getfilesize(filename, f)
            nloops = int(fsize / chunk_size) + (1 if fsize % chunk_size > 0 else 0)
            for i in range(nloops):
                headers, post_data, fp = API._chunk_media('append', filename, self.max_size_chunked, chunk_size=chunk_size, f=fp, media_id=media_info.media_id, segment_index=i, is_direct_message=is_direct_message)
                kwargs.update({ 'headers': headers, 'post_data': post_data, 'parser': RawParser() })
                # The APPEND command returns an empty response body
                bind_api(
                    api=self,
                    path='/media/upload.json',
                    method='POST',
                    payload_type='media',
                    allowed_param=[],
                    require_auth=True,
                    upload_api=True
                )(*args, **kwargs)
            # When all chunks have been sent, we can finalize.
            headers, post_data, fp = API._chunk_media('finalize', filename, self.max_size_chunked, media_id=media_info.media_id, is_direct_message=is_direct_message)
            kwargs = {'headers': headers, 'post_data': post_data}

            # The FINALIZE command returns media information
            return bind_api(
                api=self,
                path='/media/upload.json',
                method='POST',
                payload_type='media',
                allowed_param=[],
                require_auth=True,
                upload_api=True
            )(*args, **kwargs)
        else:
            return media_info
1282014
def save_as(self, filename):
        
        with open(filename, 'w+b') as f:
            for chunk in self._download():
                f.write(chunk)
475173
def serve_file(self, private_file):
        
        response = self.server_class().serve(private_file)

        if self.content_disposition:
            # Join syntax works in all Python versions. Python 3 doesn't support b'..'.format(),
            # and % formatting was added for bytes in 3.5: https://bugs.python.org/issue3982
            filename = self.get_content_disposition_filename(private_file)
            response['Content-Disposition'] = b'; '.join([
                self.content_disposition.encode(), self._encode_filename_header(filename)
            ])

        return response