def getfile(self, mode=None, prefetch=False): """Returns a file object. By default the file is fetched on demand but if prefetch is enabled the file is fully prefetched into a tempfile before reading can happen. """ impl = self._get_chunked_blob(mode, prefetch) return FileObj(impl, self.name)
def getfile(self, releasefile): cutoff = options.get("releasefile.cache-limit") file_size = releasefile.file.size if file_size < cutoff: metrics.timing("release_file.cache.get.size", file_size, tags={"cutoff": True}) return releasefile.file.getfile() file_id = str(releasefile.file_id) organization_id = str(releasefile.organization_id) file_path = os.path.join(self.cache_path, organization_id, file_id) hit = True try: os.stat(file_path) except OSError as e: if e.errno != errno.ENOENT: raise releasefile.file.save_to(file_path) hit = False metrics.timing("release_file.cache.get.size", file_size, tags={ "hit": hit, "cutoff": False }) return FileObj(open(file_path, "rb"))
def getfile(self, *args, **kwargs): return FileObj( ChunkedFileBlobIndexWrapper( FileBlobIndex.objects.filter( file=self, ).select_related('blob').order_by('offset'), mode=kwargs.get('mode'), ), self.name)
def getfile(self, *args, **kwargs): if self.blob: return self.blob.getfile() return FileObj( ChunkedFileBlobIndexWrapper( FileBlobIndex.objects.filter( file=self, ).select_related('blob').order_by('offset')), 'rb')
def getfile(self, mode=None, prefetch=False, as_tempfile=False): """Returns a file object. By default the file is fetched on demand but if prefetch is enabled the file is fully prefetched into a tempfile before reading can happen. Additionally if `as_tempfile` is passed a NamedTemporaryFile is returned instead which can help in certain situations where a tempfile is necessary. """ if as_tempfile: prefetch = True impl = self._get_chunked_blob(mode, prefetch) if as_tempfile: return impl.detach_tempfile() return FileObj(impl, self.name)
def getfile(self, mode=None, prefetch=False): cfbiw = ChunkedFileBlobIndexWrapper(FileBlobIndex.objects.filter( file=self, ).select_related('blob').order_by('offset'), mode=mode, prefetch=prefetch) return FileObj(cfbiw, self.name)