Calculate optimal part size for multipart uploads.

    :param length: Input length to calculate part size of.
    :return: Optimal part size.
355063
def optimal_part_info(length, part_size):
    
    # object size is '-1' set it to 5TiB.
    if length == -1:
        length = MAX_MULTIPART_OBJECT_SIZE
    if length > MAX_MULTIPART_OBJECT_SIZE:
        raise InvalidArgumentError('Input content size is bigger '
                                   ' than allowed maximum of 5TiB.')

    # honor user configured size
    if part_size != MIN_PART_SIZE:
        part_size_float = float(part_size)
    else:
        # Use floats for part size for all calculations to avoid
        # overflows during float64 to int64 conversions.
        part_size_float = math.ceil(length/MAX_MULTIPART_COUNT)
        part_size_float = (math.ceil(part_size_float/part_size)
                        * part_size)
    # Total parts count.
    total_parts_count = int(math.ceil(length/part_size_float))
    # Part size.
    part_size = int(part_size_float)
    # Last part size.
    last_part_size = length - int(total_parts_count-1)*part_size
    return total_parts_count, part_size, last_part_size
1174234
def size(self):
        
        if self._instrs is []:
            return None

        return sum([instr.size for instr in self._instrs])
1227316
def setMaximumLength( self, length ):
        
        self._maximumLength = length
        self._filenames = self._filenames[:length]
        self.refresh()
864331
def multipart_uploadpart(self, multipart):
        
        content_length, part_number, stream, content_type, content_md5, tags =\
            current_files_rest.multipart_partfactory()

        if content_length:
            ck = multipart.last_part_size if \
                part_number == multipart.last_part_number \
                else multipart.chunk_size

            if ck != content_length:
                raise MultipartInvalidChunkSize()

        # Create part
        try:
            p = Part.get_or_create(multipart, part_number)
            p.set_contents(stream)
            db.session.commit()
        except Exception:
            # We remove the Part since incomplete data may have been written to
            # disk (e.g. client closed connection etc.) so it must be
            # reuploaded.
            db.session.rollback()
            Part.delete(multipart, part_number)
            raise
        return self.make_response(
            data=p,
            context={
                'class': Part,
            },
            etag=p.checksum
        )
377220
def size(self, minimum: int = 1, maximum: int = 100) -> str:
        
        num = self.random.randint(minimum, maximum)
        unit = self.random.choice(
            ['bytes', 'kB', 'MB', 'GB', 'TB'])

        return '{num} {unit}'.format(
            num=num,
            unit=unit,
        )
159821
def calculate_size(name, permits):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    return data_size
369081
private static int[] calculateMultipartSize(long size)
    throws InvalidArgumentException {
    if (size > MAX_OBJECT_SIZE) {
      throw new InvalidArgumentException("size " + size + " is greater than allowed size 5TiB");
    }

    double partSize = Math.ceil((double) size / MAX_MULTIPART_COUNT);
    partSize = Math.ceil(partSize / MIN_MULTIPART_SIZE) * MIN_MULTIPART_SIZE;

    double partCount = Math.ceil(size / partSize);

    double lastPartSize = partSize - (partSize * partCount - size);
    if (lastPartSize == 0.0) {
      lastPartSize = partSize;
    }

    return new int[] { (int) partSize, (int) partCount, (int) lastPartSize };
  }
889673
def block_size(self):
        
        bs = self.attributes['block_size']
        if isinstance(bs, six.string_types):
            bs = shlex.split(bs)
        bs = [str(e) for e in bs]
        return bs
700260
def get_size(self):
        
        if self._size is None:
            self._size = self._filepath.stat().st_size
        return self._size
1115401
def calculate_size(name, items):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    for items_item in items:
        data_size += calculate_size_data(items_item)
    return data_size
529059
def calculate_size(name, batch_size):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    return data_size
1278465
def filesize(self):
        
        if self.from_stdin:
            return None
        if not self._filesize:
            self._calculate_bounds()
        return self._filesize
610964
def _upload_in_splits( self, destination_folder_id, source_path, preflight_check, verbose = True, chunked_upload_threads = 5 ):
        '''
        
        '''
        file_size = os.stat(source_path).st_size
        split_size = BOX_MAX_FILE_SIZE

        # Make sure that the last split piece is still big enough for a chunked upload
        while file_size % split_size < BOX_MIN_CHUNK_UPLOAD_SIZE:
            split_size -= 1000
            if split_size < BOX_MIN_CHUNK_UPLOAD_SIZE:
                raise Exception('Lazy programming error')

        split_start_byte = 0
        part_count = 0
        uploaded_file_ids = []
        while split_start_byte < file_size:
            dest_file_name = '{0}.part{1}'.format( os.path.basename(source_path), part_count)
            prev_uploaded_file_ids = self.find_file( destination_folder_id, dest_file_name )
            if len( prev_uploaded_file_ids ) == 1:
                if verbose:
                    print ( '\nSkipping upload of split {0} of {1}; already exists'.format( part_count + 1, math.ceil(file_size / split_size) ) )
                uploaded_file_ids.extend( prev_uploaded_file_ids )
            else:
                if verbose:
                    print ( '\nUploading split {0} of {1}'.format( part_count + 1, math.ceil(file_size / split_size) ) )
                uploaded_file_ids.append( self._chunked_upload(
                    destination_folder_id, source_path,
                    dest_file_name = dest_file_name,
                    split_start_byte = split_start_byte,
                    file_size = min(split_size, file_size - split_start_byte), # Take the min of file_size - split_start_byte so that the last part of a split doesn't read into the next split
                    preflight_check = preflight_check,
                    verbose = verbose,
                    upload_threads = chunked_upload_threads,
                ) )
            part_count += 1
            split_start_byte += split_size

        return uploaded_file_ids
272006
def calculate_size(name, expected, updated):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += BOOLEAN_SIZE_IN_BYTES
    if expected is not None:
        data_size += calculate_size_data(expected)
    data_size += BOOLEAN_SIZE_IN_BYTES
    if updated is not None:
        data_size += calculate_size_data(updated)
    return data_size
1029904
def piece_file(input_f, chunk_size):
        
        chunk = input_f.read(chunk_size)
        total_bytes = 0
        while chunk:
            yield chunk
            chunk = input_f.read(chunk_size)
            total_bytes += len(chunk)
1207752
def size(self):
        

        size = 0
        try:
            tip = self.get_changeset()
            for topnode, dirs, files in tip.walk('/'):
                for f in files:
                    size += tip.get_file_size(f.path)
                for dir in dirs:
                    for f in files:
                        size += tip.get_file_size(f.path)

        except RepositoryError:
            pass
        return size
1136973
def size(self):
    
    if self._size is None:
      self._size = 0
      for csv_file in self.files:
        self._size += sum(1 if line else 0 for line in _util.open_local_or_gcs(csv_file, 'r'))

    return self._size