-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6fbe33
commit d8adef7
Showing
128 changed files
with
989 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "products/ASC.Files/Server/DocStore"] | ||
path = products/ASC.Files/Server/DocStore | ||
url = https://github.com/ONLYOFFICE/document-templates | ||
branch = main/community-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
products/ASC.Files/Core/Core/Compress/CompressToArchive.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* | ||
* (c) Copyright Ascensio System Limited 2010-2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
using ASC.Common; | ||
using ASC.Web.Files.Classes; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ASC.Web.Files.Core.Compress | ||
{ | ||
/// <summary> | ||
/// Archives the data stream in the format selected in the settings | ||
/// </summary> | ||
[Scope] | ||
public class CompressToArchive : ICompress | ||
{ | ||
private readonly ICompress compress; | ||
|
||
internal static string TarExt = ".tar.gz"; | ||
internal static string ZipExt = ".zip"; | ||
private static List<string> Exts = new List<string>(2) { TarExt, ZipExt }; | ||
|
||
public CompressToArchive(FilesSettingsHelper filesSettings, CompressToTarGz compressToTarGz, CompressToZip compressToZip) | ||
{ | ||
compress = filesSettings.DownloadTarGz | ||
? compressToTarGz | ||
: compressToZip; | ||
} | ||
|
||
public static string GetExt(IServiceProvider serviceProvider, string ext) | ||
{ | ||
if (Exts.Contains(ext)) return ext; | ||
using var zip = serviceProvider.GetService<CompressToArchive>(); | ||
return zip.ArchiveExtension; | ||
} | ||
|
||
public void SetStream(Stream stream) => compress.SetStream(stream); | ||
|
||
/// <summary> | ||
/// The record name is created (the name of a separate file in the archive) | ||
/// </summary> | ||
/// <param name="title">File name with extension, this name will have the file in the archive</param> | ||
public void CreateEntry(string title) => compress.CreateEntry(title); | ||
|
||
/// <summary> | ||
/// Transfer the file itself to the archive | ||
/// </summary> | ||
/// <param name="readStream">File data</param> | ||
public void PutStream(Stream readStream) => compress.PutStream(readStream); | ||
|
||
/// <summary> | ||
/// Put an entry on the output stream. | ||
/// </summary> | ||
public void PutNextEntry() => compress.PutNextEntry(); | ||
|
||
/// <summary> | ||
/// Closes the current entry. | ||
/// </summary> | ||
public void CloseEntry() => compress.CloseEntry(); | ||
|
||
/// <summary> | ||
/// Resource title (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string Title => compress.Title; | ||
|
||
/// <summary> | ||
/// Extension the archive (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string ArchiveExtension => compress.ArchiveExtension; | ||
|
||
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> | ||
public void Dispose() => compress.Dispose(); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
products/ASC.Files/Core/Core/Compress/CompressToTarGz.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* | ||
* (c) Copyright Ascensio System Limited 2010-2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System.IO; | ||
using System.Text; | ||
|
||
using ASC.Common; | ||
|
||
using ICSharpCode.SharpZipLib.GZip; | ||
using ICSharpCode.SharpZipLib.Tar; | ||
|
||
namespace ASC.Web.Files.Core.Compress | ||
{ | ||
/// <summary> | ||
/// Archives the data stream into the format .tar.gz | ||
/// </summary> | ||
public class CompressToTarGz : ICompress | ||
{ | ||
private GZipOutputStream gzoStream; | ||
private TarOutputStream gzip; | ||
private TarEntry tarEntry; | ||
private TempStream TempStream { get; } | ||
|
||
internal CompressToTarGz(TempStream tempStream) | ||
{ | ||
TempStream = tempStream; | ||
} | ||
|
||
/// <summary></summary> | ||
/// <param name="stream">Accepts a new stream, it will contain an archive upon completion of work</param> | ||
public void SetStream(Stream stream) | ||
{ | ||
gzoStream = new GZipOutputStream(stream) { IsStreamOwner = false }; | ||
gzip = new TarOutputStream(gzoStream, Encoding.UTF8); | ||
gzoStream.IsStreamOwner = false; | ||
} | ||
|
||
/// <summary> | ||
/// The record name is created (the name of a separate file in the archive) | ||
/// </summary> | ||
/// <param name="title">File name with extension, this name will have the file in the archive</param> | ||
public void CreateEntry(string title) | ||
{ | ||
tarEntry = TarEntry.CreateTarEntry(title); | ||
} | ||
|
||
/// <summary> | ||
/// Transfer the file itself to the archive | ||
/// </summary> | ||
/// <param name="readStream">File data</param> | ||
public void PutStream(Stream readStream) | ||
{ | ||
using (var buffered = TempStream.GetBuffered(readStream)) | ||
{ | ||
tarEntry.Size = buffered.Length; | ||
gzip.PutNextEntry(tarEntry); | ||
buffered.CopyTo(gzip); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Put an entry on the output stream. | ||
/// </summary> | ||
public void PutNextEntry() | ||
{ | ||
gzip.PutNextEntry(tarEntry); | ||
} | ||
|
||
/// <summary> | ||
/// Closes the current entry. | ||
/// </summary> | ||
public void CloseEntry() | ||
{ | ||
gzip.CloseEntry(); | ||
} | ||
|
||
/// <summary> | ||
/// Resource title (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string Title => FilesUCResource.FilesWillBeCompressedTarGz; | ||
|
||
/// <summary> | ||
/// Extension the archive (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string ArchiveExtension => CompressToArchive.TarExt; | ||
|
||
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> | ||
public void Dispose() | ||
{ | ||
gzip?.Dispose(); | ||
gzoStream?.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* | ||
* (c) Copyright Ascensio System Limited 2010-2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System.IO; | ||
|
||
using ASC.Common; | ||
|
||
using ICSharpCode.SharpZipLib.Zip; | ||
|
||
namespace ASC.Web.Files.Core.Compress | ||
{ | ||
/// <summary> | ||
/// Archives the data stream into the format .zip | ||
/// </summary> | ||
public class CompressToZip : ICompress | ||
{ | ||
private ZipOutputStream zipStream; | ||
private ZipEntry zipEntry; | ||
private TempStream TempStream { get; } | ||
|
||
internal CompressToZip(TempStream tempStream) | ||
{ | ||
TempStream = tempStream; | ||
} | ||
|
||
/// <summary> </summary> | ||
/// <param name="stream">Accepts a new stream, it will contain an archive upon completion of work</param> | ||
public void SetStream(Stream stream) | ||
{ | ||
zipStream = new ZipOutputStream(stream) { UseZip64 = UseZip64.Dynamic }; | ||
zipStream.IsStreamOwner = false; | ||
} | ||
|
||
/// <summary> | ||
/// The record name is created (the name of a separate file in the archive) | ||
/// </summary> | ||
/// <param name="title">File name with extension, this name will have the file in the archive</param> | ||
public void CreateEntry(string title) | ||
{ | ||
zipEntry = new ZipEntry(title); | ||
} | ||
|
||
/// <summary> | ||
/// Transfer the file itself to the archive | ||
/// </summary> | ||
/// <param name="readStream">File data</param> | ||
public void PutStream(Stream readStream) | ||
{ | ||
using (var buffered = TempStream.GetBuffered(readStream)) | ||
{ | ||
zipEntry.Size = buffered.Length; | ||
zipStream.PutNextEntry(zipEntry); | ||
buffered.CopyTo(zipStream); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Put an entry on the output stream. | ||
/// </summary> | ||
public void PutNextEntry() | ||
{ | ||
zipStream.PutNextEntry(zipEntry); | ||
} | ||
|
||
/// <summary> | ||
/// Closes the current entry. | ||
/// </summary> | ||
public void CloseEntry() | ||
{ | ||
zipStream.CloseEntry(); | ||
} | ||
|
||
/// <summary> | ||
/// Resource title (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string Title => FilesUCResource.FilesWillBeCompressedZip; | ||
|
||
/// <summary> | ||
/// Extension the archive (does not affect the work of the class) | ||
/// </summary> | ||
/// <returns></returns> | ||
public string ArchiveExtension => CompressToArchive.ZipExt; | ||
|
||
public void Dispose() | ||
{ | ||
zipStream?.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.