If there are fewer files than chunks, fewer than numChunks will be returned.
19470
private static Iterable<List<Map.Entry<Symbol, File>>> splitToNChunks(
      final ImmutableMap<Symbol, File> inputMap, int numChunks) {
    checkArgument(numChunks > 0);
    final List<Map.Entry<Symbol, File>> emptyChunk = ImmutableList.of();

    if (inputMap.isEmpty()) {
      return Collections.nCopies(numChunks, emptyChunk);
    }

    final int chunkSize = IntMath.divide(inputMap.size(), numChunks, RoundingMode.UP);
    final ImmutableList<List<Map.Entry<Symbol, File>>> chunks =
        ImmutableList.copyOf(splitToChunksOfFixedSize(inputMap, chunkSize));
    if (chunks.size() == numChunks) {
      return chunks;
    } else {
      // there weren't enough elements to make the desired number of chunks, so we need to
      // pad with empty chunks
      final int shortage = numChunks - chunks.size();
      final List<List<Map.Entry<Symbol, File>>> padding = Collections.nCopies(shortage, emptyChunk);
      return Iterables.concat(chunks, padding);
    }
  }
306784
def readchunks(path, chunksize=1048576)
      open(path) { |source|
        size = source.length
        index = 0
        while index < size
          yield source.read(index, chunksize)
          index += chunksize
        end
      }
    end
79793
@Override
    protected boolean fetchMore () throws CIFSException {
        this.nextRequest.reset(this.response.getResumeKey(), this.response.getLastName());
        this.response.reset();
        try {
            getTreeHandle().send(this.nextRequest, this.response);
            return this.response.getStatus() != NtStatus.NT_STATUS_NO_MORE_FILES;
        }
        catch ( SmbException e ) {
            if ( e.getNtStatus() == NtStatus.NT_STATUS_NO_MORE_FILES ) {
                log.debug("No more entries", e);
                return false;
            }
            throw e;
        }
    }
128037
def read_chunks(stream, block_size=2**10):
    
    while True:
        chunk = stream.read(block_size)
        if not chunk:
            break
        yield chunk
231386
private void read_block_sizes_from_disk(boolean coalesce_blocks)
    throws IOException
    {
        long addr = FIRST_TAIL;
        int length;
        long new_tail = tail_ptr;

        while (addr < tail_ptr) {
            seek(addr);
            if (coalesce_blocks) {
                length = combine_blocks(addr);
            } else {
                length = readInt();
            }
            if (length > 0) {
                if ((length + addr >= tail_ptr) && (!readOnly)) {
                    // add last block to tail
                    new_tail = addr;
                } else {
                    add_to_freelist(addr, length);
                }
            } else {
                length = - length;
                allocated_blocks++;
                allocated_words += length;
            }
            addr = addr + length;
        }
        if ((new_tail != tail_ptr) && (!readOnly)) {
            tail_ptr = new_tail;
            seek(TAIL_DPTR);
            writeLong(tail_ptr);
        }

    }
30821
function aggregateCoverage(files) {
  var i, len, file, content, results;
  var resultsObj = getEmptyResultObject();

  for (i = 0, len = files.length; i < len; i++) {
    file = files[i];
    content = JSON.parse(fs.readFileSync(file).toString());
    resultsObj = populateCoverage(resultsObj, content);
  }

  return resultsObj;
}
1141517
def skipBytes(self, nroBytes):
        
        self.data.seek(nroBytes + self.data.tell())
93195
function(values) {
          if (values.length < 2) {
            logger.tracef("Not enough to read (not array): %s", values);
            return undefined;
          }

          return {segments: values[0], count: values[1]}
        }
68880
function (files, tolerance) {
    tolerance = tolerance || 5;
    return hashFiles.sync({files: files}).substring(0, tolerance);
  }
1268493
def bytes(self, count):
        """"""

        if count < 0:
            raise ValueError

        # fast path
        if self._bits == 0:
            data = self._fileobj.read(count)
            if len(data) != count:
                raise BitReaderError("not enough data")
            return data

        return bytes(bytearray(self.bits(8) for _ in xrange(count)))
526594
def is_valid_chunksize(chunk_size):
        """"""
        min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
        max_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MAX']
        return chunk_size >= min_csize and chunk_size <= max_csize
253809
def file_chunks(self, fp):
        
        fsize = utils.file_size(fp)
        offset = 0
        if hasattr(fp, 'readinto'):
            while offset < fsize:
                nb = fp.readinto(self._internal)
                yield self.buf[:nb]
                offset += nb
        else:
            while offset < fsize:
                nb = min(self.chunk_size, fsize - offset)
                yield fp.read(nb)
                offset += nb
466694
def files(self, paths, access=None, extensions=None, minsize=None):
        """"""
        self.failures = [path for path in paths if not
                         isvalid(path, access, extensions, 'file', minsize)]

        return not self.failures
1135297
def run_chunked(self):
        '''
        
        '''
        files, empty_dirs = self._list_files()
        dest = self.opts['dest']
        gzip = self.opts['gzip']
        tgt = self.opts['tgt']
        timeout = self.opts['timeout']
        selected_target_option = self.opts.get('selected_target_option')

        dest_is_dir = bool(empty_dirs) \
            or len(files) > 1 \
            or bool(re.search(r'[\\/]$', dest))

        reader = salt.utils.gzip_util.compress_file \
            if gzip \
            else salt.utils.itertools.read_file

        _res = salt.utils.minions.CkMinions(self.opts).check_minions(
            tgt,
            tgt_type=selected_target_option or 'glob')
        minions = _res['minions']

        local = salt.client.get_local_client(self.opts['conf_file'])

        def _get_remote_path(fn_):
            if fn_ in self.opts['src']:
                # This was a filename explicitly passed on the CLI
                return os.path.join(dest, os.path.basename(fn_)) \
                    if dest_is_dir \
                    else dest
            else:
                for path in self.opts['src']:
                    relpath = os.path.relpath(fn_, path + os.sep)
                    if relpath.startswith(parent):
                        # File is not within this dir
                        continue
                    return os.path.join(dest, os.path.basename(path), relpath)
                else:  # pylint: disable=useless-else-on-loop
                    # Should not happen
                    log.error('Failed to find remote path for %s', fn_)
                    return None

        ret = {}
        parent = '..' + os.sep
        for fn_, mode in six.iteritems(files):
            remote_path = _get_remote_path(fn_)

            index = 1
            failed = {}
            for chunk in reader(fn_, chunk_size=self.opts['salt_cp_chunk_size']):
                chunk = base64.b64encode(salt.utils.stringutils.to_bytes(chunk))
                append = index > 1
                log.debug(
                    'Copying %s to %starget \'%s\' as %s%s',
                    fn_,
                    '{0} '.format(selected_target_option)
                        if selected_target_option
                        else '',
                    tgt,
                    remote_path,
                    ' (chunk #{0})'.format(index) if append else ''
                )
                args = [
                    tgt,
                    'cp.recv_chunked',
                    [remote_path, chunk, append, gzip, mode],
                    timeout,
                ]
                if selected_target_option is not None:
                    args.append(selected_target_option)

                result = local.cmd(*args)

                if not result:
                    # Publish failed
                    msg = (
                        'Publish failed.{0} It may be necessary to '
                        'decrease salt_cp_chunk_size (current value: '
                        '{1})'.format(
                            ' File partially transferred.' if index > 1 else '',
                            self.opts['salt_cp_chunk_size'],
                        )
                    )
                    for minion in minions:
                        ret.setdefault(minion, {})[remote_path] = msg
                    break

                for minion_id, minion_ret in six.iteritems(result):
                    ret.setdefault(minion_id, {})[remote_path] = minion_ret
                    # Catch first error message for a given minion, we will
                    # rewrite the results after we're done iterating through
                    # the chunks.
                    if minion_ret is not True and minion_id not in failed:
                        failed[minion_id] = minion_ret

                index += 1

            for minion_id, msg in six.iteritems(failed):
                ret[minion_id][remote_path] = msg

        for dirname in empty_dirs:
            remote_path = _get_remote_path(dirname)
            log.debug(
                'Creating empty dir %s on %starget \'%s\'',
                dirname,
                '{0} '.format(selected_target_option)  # pylint: disable=str-format-in-logging
                    if selected_target_option
                    else '',
                tgt,
            )
            args = [tgt, 'cp.recv_chunked', [remote_path, None], timeout]
            if selected_target_option is not None:
                args.append(selected_target_option)

            for minion_id, minion_ret in six.iteritems(local.cmd(*args)):
                ret.setdefault(minion_id, {})[remote_path] = minion_ret

        return ret
1180232
def read_in_chunks(file_object, chunk_size=CHUNK_SIZE):
    """"""
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data
238455
@Override
    public long alloc(int chunks, long prevPos, int prevChunks) {
        long ret = s.allocReturnCode(chunks);
        if (prevPos >= 0)
            s.free(prevPos, prevChunks);
        if (ret >= 0)
            return ret;
        while (true) {
            s.nextTier();
            ret = s.allocReturnCode(chunks);
            if (ret >= 0)
                return ret;
        }
    }
1018570
function isEmpty(files, dir, acc, opts) {
  var filter = opts.filter || isGarbageFile;
  for (const file of files) {
    const fp = path.join(dir, file);

    if (opts.dryRun && acc.indexOf(fp) !== -1) {
      continue;
    }
    if (filter(fp) === false) {
      return false;
    }
  }
  return true;
}