Create an instance of `File`.
173429
function File(file, options) {
  Item.call(this, file, options);
  this.initFile(file);
  return file;
}
1329570
public static void createFile(File file) throws Exception {
    File dir = new File(file.getAbsolutePath().replace(File.separator + file.getName(), ""));
    if(!dir.exists()) {
      if(!dir.mkdirs()) {
        throw new Exception("Can't create dirs "+dir);
      }
    }
    file.createNewFile();
  }
53113
def new_file(self, path: str, checksum: str=None, to_archive: bool=False,
                 tags: List[models.Tag]=None) -> models.File:
        """"""
        new_file = self.File(path=path, checksum=checksum, to_archive=to_archive, tags=tags)
        return new_file
1153239
def _create_file(path=''):
        '''  '''
        from os.path import isfile
        if not isfile(path): # only do the following if the file doesn't exist yet
            from os import chmod
            from stat import S_IRUSR, S_IWUSR

            open(path, "a").close()  # create the file
            attempt(lambda: chmod(path, (S_IRUSR | S_IWUSR)))
772293
def _init_file(self):
        """"""
        header_length = 2*SECTOR_LENGTH
        if self.size > header_length:
            self.file.truncate(header_length)
        self.file.seek(0)
        self.file.write(header_length*b'\x00')
        self.size = header_length
109064
def _setfile(self, filename, length, offset):
        """"""
        source = open(filename, 'rb')
        if offset is None:
            offset = 0
        if length is None:
            length = os.path.getsize(source.name) * 8 - offset
        byteoffset, offset = divmod(offset, 8)
        bytelength = (length + byteoffset * 8 + offset + 7) // 8 - byteoffset
        m = MmapByteArray(source, bytelength, byteoffset)
        if length + byteoffset * 8 + offset > m.filelength * 8:
            raise CreationError("File is not long enough for specified "
                                "length and offset.")
        self._datastore = ConstByteStore(m, length, offset)
739423
def copy_contents(self, fileinstance, progress_callback=None,
                      chunk_size=None, **kwargs):
        """"""
        if not fileinstance.readable:
            raise ValueError('Source file instance is not readable.')
        if not self.size == 0:
            raise ValueError('File instance has data.')

        self.set_uri(
            *self.storage(**kwargs).copy(
                fileinstance.storage(**kwargs),
                chunk_size=chunk_size,
                progress_callback=progress_callback))
1369430
def create(self):
        
        fdint = os.open(self.path, (os.O_EXCL |
                                    os.O_CREAT |
                                    os.O_RDWR))

        # XXX TODO: 'name' attribute of returned files is not mutable or
        # settable via fdopen, so this file is slighly less functional than the
        # one returned from 'open' by default.  send a patch to Python...

        return os.fdopen(fdint, 'w+b')
1318251
public static FileCreationState newFile(final File file) throws IOException
	{
		FileCreationState fileCreationState = FileCreationState.ALREADY_EXISTS;
		if (!file.exists())
		{
			fileCreationState = FileCreationState.FAILED;
			newParentDirectories(file);
			if (file.createNewFile())
			{
				fileCreationState = FileCreationState.CREATED;
			}
		}
		return fileCreationState;
	}
1312035
def fromfile(file, dtype, count, *args, **kwargs):
    """"""

    try:
        return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs)
    except (TypeError, IOError, UnsupportedOperation):
        return np.frombuffer(
            file.read(count * np.dtype(dtype).itemsize),
            dtype=dtype, count=count, *args, **kwargs)
60189
def makefile(self, mode='r', bufsize=-1):
        ''
        sockfile = gsock.SocketFile.__new__(gsock.SocketFile)
        gfiles.FileBase.__init__(sockfile)
        sockfile._sock = self
        sockfile.mode = mode
        if bufsize > 0:
            sockfile.CHUNKSIZE = bufsize
        return sockfile
619397
def init_file(self, filename, lines, expected, line_offset):
        """"""
        self.filename = filename
        self.lines = lines
        self.expected = expected or ()
        self.line_offset = line_offset
        self.file_errors = 0
        self.counters['files'] += 1
        self.counters['physical lines'] += len(lines)
1332331
def from_file(self, filename):
        """"""
        f = open(filename, 'rb')
        while True:
            data = f.read(10480)
            if not data:
                break
            self.update(data)
        f.close()
368500
def as_file(self):
        """"""
        use_data_if_no_file = not self._file and self._data
        if use_data_if_no_file:
            if self._base64_file_content:
                if isinstance(self._data, str):
                    content = self._data.encode()
                else:
                    content = self._data
                self._file = _create_temp_file_with_content(
                    base64.standard_b64decode(content))
            else:
                self._file = _create_temp_file_with_content(self._data)
        if self._file and not os.path.isfile(self._file):
            raise ConfigException("File does not exists: %s" % self._file)
        return self._file
922278
def fromFile(cls, filename):
        
        self = cls.__new__(cls)  # new instance which does not call __init__

        start = _time()

        savedData = _loads(_open(filename, "r").read())

        # load common attributes
        self.string, self.unit, self.voc, self.vocSize, self.SA, features = savedData[:6]
        self.length = len(self.SA)

        # determine token delimiter
        if self.unit == UNIT_WORD:
            self.tokSep = " "
        elif self.unit in (UNIT_CHARACTER, UNIT_BYTE):
            self.tokSep = ""
        else:
            raise Exception("Unknown unit type identifier:", self.unit)

        # recompute tokId based on voc
        self.tokId = dict((char, iChar) for iChar, char in enumerate(self.voc))
        self.nbSentences = self.string.count(self.tokId.get("\n", 0))

        # Load features
        self.features = []
        for featureName, (featureValues, featureDefault) in zip(features, savedData[6:]):
            self.addFeatureSA((lambda _: featureValues), name=featureName, default=featureDefault)

        self.fromFileTime = _time() - start
        if _trace: print >> _stderr, "fromFileTime %.2fs" % self.fromFileTime
        return self
146299
def _put_file(self, file):
        """"""

        post_params = {
            'file_size': file.size,
            'file_hash': file.md5hash(),
            'content_type': self._get_content_type(file),

        }

        headers = self._request_headers('PUT', file.prefixed_name, post_params=post_params)

        with closing(HTTPConnection(self.netloc)) as conn:
            conn.request('PUT', file.prefixed_name, file.read(), headers=headers)
            response = conn.getresponse()

            if response.status not in (200,):
                raise S3IOError(
                    'py3s3 PUT error. '
                    'Response status: {}. '
                    'Reason: {}. '
                    'Response Text: \n'
                    '{}'.format(response.status, response.reason, response.read()))
684585
def makefile(self, mode='r', bufsize=-1):
        
        return _fileobject(Socket(
            _sock=self._fd._sock, 
            _timeout=self._timeout, 
            _proactor_added=self._proactor_added
        ), mode, bufsize)