diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 680486f..27afd47 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -293,8 +293,12 @@ getPathObjectId(git, path, revCommit).map { objectId => if(raw){ // Download - JGitUtil.getContentFromId(git, objectId, true).map { bytes => - RawData("application/octet-stream", bytes) + JGitUtil.getObjectLoaderFromId(git, objectId){ loader => + //RawData("application/octet-stream", bytes) + contentType = "application/octet-stream" + response.setContentLength(loader.getSize.toInt) + loader.copyTo(response.getOutputStream) + () } getOrElse NotFound } else { html.blob(id, repository, path.split("/").toList, diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index 3eef33d..43c2521 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -713,7 +713,7 @@ def getContentFromId(git: Git, id: ObjectId, fetchLargeFile: Boolean): Option[Array[Byte]] = try { using(git.getRepository.getObjectDatabase){ db => val loader = db.open(id) - if(fetchLargeFile == false && FileUtil.isLarge(loader.getSize)){ + if(loader.isLarge || (fetchLargeFile == false && FileUtil.isLarge(loader.getSize))){ None } else { Some(loader.getBytes) @@ -724,6 +724,22 @@ } /** + * Get objectLoader of the given object id from the Git repository. + * + * @param git the Git object + * @param id the object id + * @param f the function process ObjectLoader + * @return None if object does not exist + */ + def getObjectLoaderFromId[A](git: Git, id: ObjectId)(f: ObjectLoader => A):Option[A] = try { + using(git.getRepository.getObjectDatabase){ db => + Some(f(db.open(id))) + } + } catch { + case e: MissingObjectException => None + } + + /** * Returns all commit id in the specified repository. */ def getAllCommitIds(git: Git): Seq[String] = if(isEmpty(git)) {