diff options
author | 2024-07-12 09:39:47 +0000 | |
---|---|---|
committer | 2024-07-12 09:39:47 +0000 | |
commit | cde2fb6244a791b3c5b746112e3a8be3a79f39a4 (patch) | |
tree | 6079d6fb66d90ffbe8c1623525bb86829c162459 /vendor/codeberg.org | |
parent | [chore] Add interaction policy gtsmodels (#3075) (diff) | |
download | gotosocial-cde2fb6244a791b3c5b746112e3a8be3a79f39a4.tar.xz |
[feature] support processing of (many) more media types (#3090)
* initial work replacing our media decoding / encoding pipeline with ffprobe + ffmpeg
* specify the video codec to use when generating static image from emoji
* update go-storage library (fixes incompatibility after updating go-iotools)
* maintain image aspect ratio when generating a thumbnail for it
* update readme to show go-ffmpreg
* fix a bunch of media tests, move filesize checking to callers of media manager for more flexibility
* remove extra debug from error message
* fix up incorrect function signatures
* update PutFile to just use regular file copy, as changes are file is on separate partition
* fix remaining tests, remove some unneeded tests now we're working with ffmpeg/ffprobe
* update more tests, add more code comments
* add utilities to generate processed emoji / media outputs
* fix remaining tests
* add test for opus media file, add license header to utility cmds
* limit the number of concurrently available ffmpeg / ffprobe instances
* reduce number of instances
* further reduce number of instances
* fix envparsing test with configuration variables
* update docs and configuration with new media-{local,remote}-max-size variables
Diffstat (limited to 'vendor/codeberg.org')
26 files changed, 2168 insertions, 852 deletions
diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/LICENSE b/vendor/codeberg.org/gruf/go-ffmpreg/LICENSE index dba13ed2d..f288702d2 100644 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/LICENSE +++ b/vendor/codeberg.org/gruf/go-ffmpreg/LICENSE @@ -1,21 +1,23 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. + The GNU General Public License is a free, copyleft license for +software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to +the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -24,34 +26,44 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. @@ -60,7 +72,7 @@ modification follow. 0. Definitions. - "This License" refers to version 3 of the GNU Affero General Public License. + "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. @@ -537,45 +549,35 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. + 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single +under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General +Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published +GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's +versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. @@ -633,29 +635,40 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by + it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -<http://www.gnu.org/licenses/>. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm Binary files differnew file mode 100644 index 000000000..36626ca05 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/lib.go b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/lib.go new file mode 100644 index 000000000..4c1400114 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/lib.go @@ -0,0 +1,38 @@ +package ffmpeg + +import ( + _ "embed" + "os" + + "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/experimental" +) + +func init() { + // Check for WASM source file path. + path := os.Getenv("FFMPEG_WASM") + if path == "" { + return + } + + var err error + + // Read file into memory. + B, err = os.ReadFile(path) + if err != nil { + panic(err) + } +} + +// CoreFeatures is the WebAssembly Core specification +// features this embedded binary was compiled with. +const CoreFeatures = api.CoreFeatureSIMD | + api.CoreFeatureBulkMemoryOperations | + api.CoreFeatureNonTrappingFloatToIntConversion | + api.CoreFeatureMutableGlobal | + api.CoreFeatureReferenceTypes | + api.CoreFeatureSignExtensionOps | + experimental.CoreFeaturesThreads + +//go:embed ffmpeg.wasm +var B []byte diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm Binary files differnew file mode 100644 index 000000000..ebef6767a --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/lib.go b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/lib.go new file mode 100644 index 000000000..b2ffb3c54 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/lib.go @@ -0,0 +1,38 @@ +package ffprobe + +import ( + _ "embed" + "os" + + "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/experimental" +) + +func init() { + // Check for WASM source file path. + path := os.Getenv("FFPROBE_WASM") + if path == "" { + return + } + + var err error + + // Read file into memory. + B, err = os.ReadFile(path) + if err != nil { + panic(err) + } +} + +// CoreFeatures is the WebAssembly Core specification +// features this embedded binary was compiled with. +const CoreFeatures = api.CoreFeatureSIMD | + api.CoreFeatureBulkMemoryOperations | + api.CoreFeatureNonTrappingFloatToIntConversion | + api.CoreFeatureMutableGlobal | + api.CoreFeatureReferenceTypes | + api.CoreFeatureSignExtensionOps | + experimental.CoreFeaturesThreads + +//go:embed ffprobe.wasm +var B []byte diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/ffmpeg/ffmpeg.go b/vendor/codeberg.org/gruf/go-ffmpreg/ffmpeg/ffmpeg.go new file mode 100644 index 000000000..d5f4b2b9c --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/ffmpeg/ffmpeg.go @@ -0,0 +1,109 @@ +package ffmpeg + +import ( + "context" + + "codeberg.org/gruf/go-ffmpreg/embed/ffmpeg" + "codeberg.org/gruf/go-ffmpreg/internal" + "codeberg.org/gruf/go-ffmpreg/util" + "codeberg.org/gruf/go-ffmpreg/wasm" + "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" +) + +// pool of WASM module instances. +var pool = wasm.InstancePool{ + Instantiator: wasm.Instantiator{ + + // WASM module name. + Module: "ffmpeg", + + // Per-instance WebAssembly runtime (with shared cache). + Runtime: func(ctx context.Context) wazero.Runtime { + + // Prepare config with cache. + cfg := wazero.NewRuntimeConfig() + cfg = cfg.WithCoreFeatures(ffmpeg.CoreFeatures) + cfg = cfg.WithCompilationCache(internal.Cache) + + // Instantiate runtime with our config. + rt := wazero.NewRuntimeWithConfig(ctx, cfg) + + // Prepare default "env" host module. + env := rt.NewHostModuleBuilder("env") + env = env.NewFunctionBuilder(). + WithGoModuleFunction( + api.GoModuleFunc(util.Wasm_Tempnam), + []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, + []api.ValueType{api.ValueTypeI32}, + ). + Export("tempnam") + + // Instantiate "env" module in our runtime. + _, err := env.Instantiate(context.Background()) + if err != nil { + panic(err) + } + + // Instantiate the wasi snapshot preview 1 in runtime. + _, err = wasi_snapshot_preview1.Instantiate(ctx, rt) + if err != nil { + panic(err) + } + + return rt + }, + + // Per-run module configuration. + Config: wazero.NewModuleConfig, + + // Embedded WASM. + Source: ffmpeg.B, + }, +} + +// Precompile ensures at least compiled ffmpeg +// instance is available in the global pool. +func Precompile(ctx context.Context) error { + inst, err := pool.Get(ctx) + if err != nil { + return err + } + pool.Put(inst) + return nil +} + +// Get fetches new ffmpeg instance from pool, prefering cached if available. +func Get(ctx context.Context) (*wasm.Instance, error) { return pool.Get(ctx) } + +// Put places the given ffmpeg instance in pool. +func Put(inst *wasm.Instance) { pool.Put(inst) } + +// Run will run the given args against an ffmpeg instance from pool. +func Run(ctx context.Context, args wasm.Args) (uint32, error) { + inst, err := pool.Get(ctx) + if err != nil { + return 0, err + } + rc, err := inst.Run(ctx, args) + pool.Put(inst) + return rc, err +} + +// Cached returns a cached instance (if any) from pool. +func Cached() *wasm.Instance { return pool.Cached() } + +// Free drops all instances +// cached in instance pool. +func Free() { + ctx := context.Background() + for { + inst := pool.Cached() + if inst == nil { + return + } + _ = inst.Close(ctx) + } + +} diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/ffprobe/ffprobe.go b/vendor/codeberg.org/gruf/go-ffmpreg/ffprobe/ffprobe.go new file mode 100644 index 000000000..e8178e97a --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/ffprobe/ffprobe.go @@ -0,0 +1,108 @@ +package ffprobe + +import ( + "context" + + "codeberg.org/gruf/go-ffmpreg/embed/ffprobe" + "codeberg.org/gruf/go-ffmpreg/internal" + "codeberg.org/gruf/go-ffmpreg/util" + "codeberg.org/gruf/go-ffmpreg/wasm" + "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" +) + +// pool of WASM module instances. +var pool = wasm.InstancePool{ + Instantiator: wasm.Instantiator{ + + // WASM module name. + Module: "ffprobe", + + // Per-instance WebAssembly runtime (with shared cache). + Runtime: func(ctx context.Context) wazero.Runtime { + + // Prepare config with cache. + cfg := wazero.NewRuntimeConfig() + cfg = cfg.WithCoreFeatures(ffprobe.CoreFeatures) + cfg = cfg.WithCompilationCache(internal.Cache) + + // Instantiate runtime with our config. + rt := wazero.NewRuntimeWithConfig(ctx, cfg) + + // Prepare default "env" host module. + env := rt.NewHostModuleBuilder("env") + env = env.NewFunctionBuilder(). + WithGoModuleFunction( + api.GoModuleFunc(util.Wasm_Tempnam), + []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, + []api.ValueType{api.ValueTypeI32}, + ). + Export("tempnam") + + // Instantiate "env" module in our runtime. + _, err := env.Instantiate(context.Background()) + if err != nil { + panic(err) + } + + // Instantiate the wasi snapshot preview 1 in runtime. + _, err = wasi_snapshot_preview1.Instantiate(ctx, rt) + if err != nil { + panic(err) + } + + return rt + }, + + // Per-run module configuration. + Config: wazero.NewModuleConfig, + + // Embedded WASM. + Source: ffprobe.B, + }, +} + +// Precompile ensures at least compiled ffprobe +// instance is available in the global pool. +func Precompile(ctx context.Context) error { + inst, err := pool.Get(ctx) + if err != nil { + return err + } + pool.Put(inst) + return nil +} + +// Get fetches new ffprobe instance from pool, prefering cached if available. +func Get(ctx context.Context) (*wasm.Instance, error) { return pool.Get(ctx) } + +// Put places the given ffprobe instance in pool. +func Put(inst *wasm.Instance) { pool.Put(inst) } + +// Run will run the given args against an ffprobe instance from pool. +func Run(ctx context.Context, args wasm.Args) (uint32, error) { + inst, err := pool.Get(ctx) + if err != nil { + return 0, err + } + rc, err := inst.Run(ctx, args) + pool.Put(inst) + return rc, err +} + +// Cached returns a cached instance (if any) from pool. +func Cached() *wasm.Instance { return pool.Cached() } + +// Free drops all instances +// cached in instance pool. +func Free() { + ctx := context.Background() + for { + inst := pool.Cached() + if inst == nil { + return + } + _ = inst.Close(ctx) + } +} diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/internal/wasm.go b/vendor/codeberg.org/gruf/go-ffmpreg/internal/wasm.go new file mode 100644 index 000000000..94fdfbdde --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/internal/wasm.go @@ -0,0 +1,25 @@ +package internal + +import ( + "os" + + "github.com/tetratelabs/wazero" +) + +func init() { + var err error + + if dir := os.Getenv("WAZERO_COMPILATION_CACHE"); dir != "" { + // Use on-filesystem compilation cache given by env. + Cache, err = wazero.NewCompilationCacheWithDir(dir) + if err != nil { + panic(err) + } + } else { + // Use in-memory compilation cache. + Cache = wazero.NewCompilationCache() + } +} + +// Shared WASM compilation cache. +var Cache wazero.CompilationCache diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/util/funcs.go b/vendor/codeberg.org/gruf/go-ffmpreg/util/funcs.go new file mode 100644 index 000000000..4b584cf41 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/util/funcs.go @@ -0,0 +1,65 @@ +package util + +import ( + "context" + "os" + "path" + "strconv" + "time" + + "github.com/tetratelabs/wazero/api" +) + +// Wasm_Tempnam wraps Go_Tempnam to fulfill wazero's api.GoModuleFunc, +// the argument definition is (i32, i32) and return definition is (i32). +// NOTE: the calling module MUST have access to exported malloc / free. +func Wasm_Tempnam(ctx context.Context, mod api.Module, stack []uint64) { + dirptr := api.DecodeU32(stack[0]) + pfxptr := api.DecodeU32(stack[1]) + dir := readString(ctx, mod, dirptr, 0) + pfx := readString(ctx, mod, pfxptr, 0) + tmpstr := Go_Tempnam(dir, pfx) + tmpptr := writeString(ctx, mod, tmpstr) + stack[0] = api.EncodeU32(tmpptr) +} + +// Go_Tempname is functionally similar to C's tempnam. +func Go_Tempnam(dir, prefix string) string { + now := time.Now().Unix() + prefix = path.Join(dir, prefix) + for i := 0; i < 1000; i++ { + n := murmur2(uint32(now + int64(i))) + name := prefix + strconv.FormatUint(uint64(n), 10) + _, err := os.Stat(name) + if err == nil { + continue + } else if os.IsNotExist(err) { + return name + } else { + panic(err) + } + } + panic("too many attempts") +} + +// murmur2 is a simple uint32 murmur2 hash +// impl with fixed seed and input size. +func murmur2(k uint32) (h uint32) { + const ( + // seed ^ bitlen + s = uint32(2147483647) ^ 8 + + M = 0x5bd1e995 + R = 24 + ) + h = s + k *= M + k ^= k >> R + k *= M + h *= M + h ^= k + h ^= h >> 13 + h *= M + h ^= h >> 15 + return +} diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/util/wasm.go b/vendor/codeberg.org/gruf/go-ffmpreg/util/wasm.go new file mode 100644 index 000000000..fce41d0a0 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/util/wasm.go @@ -0,0 +1,81 @@ +package util + +import ( + "bytes" + "context" + + "github.com/tetratelabs/wazero/api" +) + +// NOTE: +// the below functions are not very well optimized +// for repeated calls. this is relying on the fact +// that the only place they get used (tempnam), is +// not called very often, should only be once per run +// so calls to ExportedFunction() and Call() instead +// of caching api.Function and using CallWithStack() +// will work out the same (if only called once). + +// maxaddr is the maximum +// wasm32 memory address. +const maxaddr = ^uint32(0) + +func malloc(ctx context.Context, mod api.Module, sz uint32) uint32 { + stack, err := mod.ExportedFunction("malloc").Call(ctx, uint64(sz)) + if err != nil { + panic(err) + } + ptr := api.DecodeU32(stack[0]) + if ptr == 0 { + panic("out of memory") + } + return ptr +} + +func free(ctx context.Context, mod api.Module, ptr uint32) { + if ptr != 0 { + mod.ExportedFunction("free").Call(ctx, uint64(ptr)) + } +} + +func view(ctx context.Context, mod api.Module, ptr uint32, n uint32) []byte { + if n == 0 { + n = maxaddr - ptr + } + mem := mod.Memory() + b, ok := mem.Read(ptr, n) + if !ok { + panic("out of range") + } + return b +} + +func read(ctx context.Context, mod api.Module, ptr, n uint32) []byte { + return bytes.Clone(view(ctx, mod, ptr, n)) +} + +func readString(ctx context.Context, mod api.Module, ptr, n uint32) string { + return string(view(ctx, mod, ptr, n)) +} + +func write(ctx context.Context, mod api.Module, b []byte) uint32 { + mem := mod.Memory() + len := uint32(len(b)) + ptr := malloc(ctx, mod, len) + ok := mem.Write(ptr, b) + if !ok { + panic("out of range") + } + return ptr +} + +func writeString(ctx context.Context, mod api.Module, str string) uint32 { + mem := mod.Memory() + len := uint32(len(str) + 1) + ptr := malloc(ctx, mod, len) + ok := mem.WriteString(ptr, str) + if !ok { + panic("out of range") + } + return ptr +} diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go new file mode 100644 index 000000000..21a080ce9 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go @@ -0,0 +1,181 @@ +package wasm + +import ( + "context" + "errors" + "io" + "sync" + + "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/sys" +) + +type Args struct { + // Standard FDs. + Stdin io.Reader + Stdout io.Writer + Stderr io.Writer + + // CLI args. + Args []string + + // Optional further module configuration function. + // (e.g. to mount filesystem dir, set env vars, etc). + Config func(wazero.ModuleConfig) wazero.ModuleConfig +} + +type Instantiator struct { + // Module ... + Module string + + // Runtime ... + Runtime func(context.Context) wazero.Runtime + + // Config ... + Config func() wazero.ModuleConfig + + // Source ... + Source []byte +} + +func (inst *Instantiator) New(ctx context.Context) (*Instance, error) { + switch { + case inst.Module == "": + panic("missing module name") + case inst.Runtime == nil: + panic("missing runtime instantiator") + case inst.Config == nil: + panic("missing module configuration") + case len(inst.Source) == 0: + panic("missing module source") + } + + // Create new host runtime. + rt := inst.Runtime(ctx) + + // Compile guest module from WebAssembly source. + mod, err := rt.CompileModule(ctx, inst.Source) + if err != nil { + return nil, err + } + + return &Instance{ + inst: inst, + wzrt: rt, + cmod: mod, + }, nil +} + +type InstancePool struct { + Instantiator + + pool []*Instance + lock sync.Mutex +} + +func (p *InstancePool) Get(ctx context.Context) (*Instance, error) { + for { + // Check for cached. + inst := p.Cached() + if inst == nil { + break + } + + // Check if closed. + if inst.IsClosed() { + continue + } + + return inst, nil + } + + // Must create new instance. + return p.Instantiator.New(ctx) +} + +func (p *InstancePool) Put(inst *Instance) { + if inst.inst != &p.Instantiator { + panic("instance and pool instantiators do not match") + } + p.lock.Lock() + p.pool = append(p.pool, inst) + p.lock.Unlock() +} + +func (p *InstancePool) Cached() *Instance { + var inst *Instance + p.lock.Lock() + if len(p.pool) > 0 { + inst = p.pool[len(p.pool)-1] + p.pool = p.pool[:len(p.pool)-1] + } + p.lock.Unlock() + return inst +} + +// Instance ... +// +// NOTE: Instance is NOT concurrency +// safe. One at a time please!! +type Instance struct { + inst *Instantiator + wzrt wazero.Runtime + cmod wazero.CompiledModule +} + +func (inst *Instance) Run(ctx context.Context, args Args) (uint32, error) { + if inst.inst == nil { + panic("not initialized") + } + + // Check instance open. + if inst.IsClosed() { + return 0, errors.New("instance closed") + } + + // Prefix binary name as argv0 to args. + cargs := make([]string, len(args.Args)+1) + copy(cargs[1:], args.Args) + cargs[0] = inst.inst.Module + + // Create base module config. + modcfg := inst.inst.Config() + modcfg = modcfg.WithName(inst.inst.Module) + modcfg = modcfg.WithArgs(cargs...) + modcfg = modcfg.WithStdin(args.Stdin) + modcfg = modcfg.WithStdout(args.Stdout) + modcfg = modcfg.WithStderr(args.Stderr) + + if args.Config != nil { + // Pass through config fn. + modcfg = args.Config(modcfg) + } + + // Instantiate the module from precompiled wasm module data. + mod, err := inst.wzrt.InstantiateModule(ctx, inst.cmod, modcfg) + + if mod != nil { + // Close module. + mod.Close(ctx) + } + + // Check for a returned exit code error. + if err, ok := err.(*sys.ExitError); ok { + return err.ExitCode(), nil + } + + return 0, err +} + +func (inst *Instance) IsClosed() bool { + return (inst.wzrt == nil || inst.cmod == nil) +} + +func (inst *Instance) Close(ctx context.Context) error { + if inst.IsClosed() { + return nil + } + err1 := inst.cmod.Close(ctx) + err2 := inst.wzrt.Close(ctx) + return errors.Join(err1, err2) +} diff --git a/vendor/codeberg.org/gruf/go-iotools/close.go b/vendor/codeberg.org/gruf/go-iotools/close.go index 3f0ee7780..f3d4814ba 100644 --- a/vendor/codeberg.org/gruf/go-iotools/close.go +++ b/vendor/codeberg.org/gruf/go-iotools/close.go @@ -2,6 +2,13 @@ package iotools import "io" +// NopCloser is an empty +// implementation of io.Closer, +// that simply does nothing! +type NopCloser struct{} + +func (NopCloser) Close() error { return nil } + // CloserFunc is a function signature which allows // a function to implement the io.Closer type. type CloserFunc func() error @@ -10,6 +17,7 @@ func (c CloserFunc) Close() error { return c() } +// CloserCallback wraps io.Closer to add a callback deferred to call just after Close(). func CloserCallback(c io.Closer, cb func()) io.Closer { return CloserFunc(func() error { defer cb() @@ -17,6 +25,7 @@ func CloserCallback(c io.Closer, cb func()) io.Closer { }) } +// CloserAfterCallback wraps io.Closer to add a callback called just before Close(). func CloserAfterCallback(c io.Closer, cb func()) io.Closer { return CloserFunc(func() (err error) { defer func() { err = c.Close() }() diff --git a/vendor/codeberg.org/gruf/go-iotools/helpers.go b/vendor/codeberg.org/gruf/go-iotools/helpers.go new file mode 100644 index 000000000..0e50e05e0 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-iotools/helpers.go @@ -0,0 +1,85 @@ +package iotools + +import "io" + +// AtEOF returns true when reader at EOF, +// this is checked with a 0 length read. +func AtEOF(r io.Reader) bool { + _, err := r.Read(nil) + return (err == io.EOF) +} + +// GetReadCloserLimit attempts to cast io.Reader to access its io.LimitedReader with limit. +func GetReaderLimit(r io.Reader) (*io.LimitedReader, int64) { + lr, ok := r.(*io.LimitedReader) + if !ok { + return nil, -1 + } + return lr, lr.N +} + +// UpdateReaderLimit attempts to update the limit of a reader for existing, newly wrapping if necessary. +func UpdateReaderLimit(r io.Reader, limit int64) (*io.LimitedReader, int64) { + lr, ok := r.(*io.LimitedReader) + if !ok { + lr = &io.LimitedReader{r, limit} + return lr, limit + } + + if limit < lr.N { + // Update existing. + lr.N = limit + } + + return lr, lr.N +} + +// GetReadCloserLimit attempts to unwrap io.ReadCloser to access its io.LimitedReader with limit. +func GetReadCloserLimit(rc io.ReadCloser) (*io.LimitedReader, int64) { + rct, ok := rc.(*ReadCloserType) + if !ok { + return nil, -1 + } + lr, ok := rct.Reader.(*io.LimitedReader) + if !ok { + return nil, -1 + } + return lr, lr.N +} + +// UpdateReadCloserLimit attempts to update the limit of a readcloser for existing, newly wrapping if necessary. +func UpdateReadCloserLimit(rc io.ReadCloser, limit int64) (io.ReadCloser, *io.LimitedReader, int64) { + + // Check for our wrapped ReadCloserType. + if rct, ok := rc.(*ReadCloserType); ok { + + // Attempt to update existing wrapped limit reader. + if lr, ok := rct.Reader.(*io.LimitedReader); ok { + + if limit < lr.N { + // Update existing. + lr.N = limit + } + + return rct, lr, lr.N + } + + // Wrap the reader type with new limit. + lr := &io.LimitedReader{rct.Reader, limit} + rct.Reader = lr + + return rct, lr, lr.N + } + + // Wrap separated types. + rct := &ReadCloserType{ + Reader: rc, + Closer: rc, + } + + // Wrap separated reader part with limit. + lr := &io.LimitedReader{rct.Reader, limit} + rct.Reader = lr + + return rct, lr, lr.N +} diff --git a/vendor/codeberg.org/gruf/go-iotools/read.go b/vendor/codeberg.org/gruf/go-iotools/read.go index 6ce2789a7..13c5e21ac 100644 --- a/vendor/codeberg.org/gruf/go-iotools/read.go +++ b/vendor/codeberg.org/gruf/go-iotools/read.go @@ -4,6 +4,16 @@ import ( "io" ) +// ReadCloserType implements io.ReadCloser +// by combining the two underlying interfaces, +// while providing an exported type to still +// access the underlying original io.Reader or +// io.Closer separately (e.g. without wrapping). +type ReadCloserType struct { + io.Reader + io.Closer +} + // ReaderFunc is a function signature which allows // a function to implement the io.Reader type. type ReaderFunc func([]byte) (int, error) @@ -22,15 +32,10 @@ func (rf ReaderFromFunc) ReadFrom(r io.Reader) (int64, error) { // ReadCloser wraps an io.Reader and io.Closer in order to implement io.ReadCloser. func ReadCloser(r io.Reader, c io.Closer) io.ReadCloser { - return &struct { - io.Reader - io.Closer - }{r, c} + return &ReadCloserType{r, c} } -// NopReadCloser wraps an io.Reader to implement io.ReadCloser with empty io.Closer implementation. +// NopReadCloser wraps io.Reader with NopCloser{} in ReadCloserType. func NopReadCloser(r io.Reader) io.ReadCloser { - return ReadCloser(r, CloserFunc(func() error { - return nil - })) + return &ReadCloserType{r, NopCloser{}} } diff --git a/vendor/codeberg.org/gruf/go-iotools/size.go b/vendor/codeberg.org/gruf/go-iotools/size.go new file mode 100644 index 000000000..f3841facf --- /dev/null +++ b/vendor/codeberg.org/gruf/go-iotools/size.go @@ -0,0 +1,25 @@ +package iotools + +type Sizer interface { + Size() int64 +} + +// SizerFunc is a function signature which allows +// a function to implement the Sizer type. +type SizerFunc func() int64 + +func (s SizerFunc) Size() int64 { + return s() +} + +type Lengther interface { + Len() int +} + +// LengthFunc is a function signature which allows +// a function to implement the Lengther type. +type LengthFunc func() int + +func (l LengthFunc) Len() int { + return l() +} diff --git a/vendor/codeberg.org/gruf/go-iotools/write.go b/vendor/codeberg.org/gruf/go-iotools/write.go index e1b44db24..2037c42af 100644 --- a/vendor/codeberg.org/gruf/go-iotools/write.go +++ b/vendor/codeberg.org/gruf/go-iotools/write.go @@ -28,7 +28,10 @@ func WriteCloser(w io.Writer, c io.Closer) io.WriteCloser { // NopWriteCloser wraps an io.Writer to implement io.WriteCloser with empty io.Closer implementation. func NopWriteCloser(w io.Writer) io.WriteCloser { - return WriteCloser(w, CloserFunc(func() error { - return nil - })) + return &nopWriteCloser{w} } + +// nopWriteCloser implements io.WriteCloser with a no-op Close(). +type nopWriteCloser struct{ io.Writer } + +func (wc *nopWriteCloser) Close() error { return nil } diff --git a/vendor/codeberg.org/gruf/go-mimetypes/README.md b/vendor/codeberg.org/gruf/go-mimetypes/README.md new file mode 100644 index 000000000..faf0fe4bb --- /dev/null +++ b/vendor/codeberg.org/gruf/go-mimetypes/README.md @@ -0,0 +1,5 @@ +# go-mimetypes + +A generated lookup map of file extensions to mimetypes, from data provided at: https://raw.githubusercontent.com/micnic/mime.json/master/index.json + +This allows determining mimetype without relying on OS mimetype lookups.
\ No newline at end of file diff --git a/vendor/codeberg.org/gruf/go-mimetypes/get-mime-types.sh b/vendor/codeberg.org/gruf/go-mimetypes/get-mime-types.sh new file mode 100644 index 000000000..0ee088c73 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-mimetypes/get-mime-types.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# Mime types JSON source +URL='https://raw.githubusercontent.com/micnic/mime.json/master/index.json' + +# Define intro to file +FILE=' +// This is an automatically generated file, do not edit +package mimetypes + + +// MimeTypes is a map of file extensions to mime types. +var MimeTypes = map[string]string{ +' + +# Set break on new-line +IFS=' +' + +for line in $(curl -fL "$URL" | grep -E '".+"\s*:\s*".+"'); do + # Trim final whitespace + line=$(echo "$line" | sed -e 's|\s*$||') + + # Ensure it ends in a comma + [ "${line%,}" = "$line" ] && line="${line}," + + # Add to file + FILE="${FILE}${line} +" +done + +# Add final statement to file +FILE="${FILE} +} + +" + +# Write to file +echo "$FILE" > 'mime.gen.go' + +# Check for valid go +gofumpt -w 'mime.gen.go'
\ No newline at end of file diff --git a/vendor/codeberg.org/gruf/go-mimetypes/mime.gen.go b/vendor/codeberg.org/gruf/go-mimetypes/mime.gen.go new file mode 100644 index 000000000..54e5b2249 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-mimetypes/mime.gen.go @@ -0,0 +1,1207 @@ +// This is an automatically generated file, do not edit +package mimetypes + +// MimeTypes is a map of file extensions to mime types. +var MimeTypes = map[string]string{ + "123": "application/vnd.lotus-1-2-3", + "1km": "application/vnd.1000minds.decision-model+xml", + "3dml": "text/vnd.in3d.3dml", + "3ds": "image/x-3ds", + "3g2": "video/3gpp2", + "3gp": "video/3gpp", + "3gpp": "video/3gpp", + "3mf": "model/3mf", + "7z": "application/x-7z-compressed", + "aab": "application/x-authorware-bin", + "aac": "audio/x-aac", + "aam": "application/x-authorware-map", + "aas": "application/x-authorware-seg", + "abw": "application/x-abiword", + "ac": "application/vnd.nokia.n-gage.ac+xml", + "acc": "application/vnd.americandynamics.acc", + "ace": "application/x-ace-compressed", + "acu": "application/vnd.acucobol", + "acutc": "application/vnd.acucorp", + "adp": "audio/adpcm", + "adts": "audio/aac", + "aep": "application/vnd.audiograph", + "afm": "application/x-font-type1", + "afp": "application/vnd.ibm.modcap", + "age": "application/vnd.age", + "ahead": "application/vnd.ahead.space", + "ai": "application/postscript", + "aif": "audio/x-aiff", + "aifc": "audio/x-aiff", + "aiff": "audio/x-aiff", + "air": "application/vnd.adobe.air-application-installer-package+zip", + "ait": "application/vnd.dvb.ait", + "ami": "application/vnd.amiga.ami", + "aml": "application/automationml-aml+xml", + "amlx": "application/automationml-amlx+zip", + "amr": "audio/amr", + "apk": "application/vnd.android.package-archive", + "apng": "image/apng", + "appcache": "text/cache-manifest", + "appinstaller": "application/appinstaller", + "application": "application/x-ms-application", + "appx": "application/appx", + "appxbundle": "application/appxbundle", + "apr": "application/vnd.lotus-approach", + "arc": "application/x-freearc", + "arj": "application/x-arj", + "asc": "application/pgp-signature", + "asf": "video/x-ms-asf", + "asm": "text/x-asm", + "aso": "application/vnd.accpac.simply.aso", + "asx": "video/x-ms-asf", + "atc": "application/vnd.acucorp", + "atom": "application/atom+xml", + "atomcat": "application/atomcat+xml", + "atomdeleted": "application/atomdeleted+xml", + "atomsvc": "application/atomsvc+xml", + "atx": "application/vnd.antix.game-component", + "au": "audio/basic", + "avci": "image/avci", + "avcs": "image/avcs", + "avi": "video/x-msvideo", + "avif": "image/avif", + "aw": "application/applixware", + "azf": "application/vnd.airzip.filesecure.azf", + "azs": "application/vnd.airzip.filesecure.azs", + "azv": "image/vnd.airzip.accelerator.azv", + "azw": "application/vnd.amazon.ebook", + "b16": "image/vnd.pco.b16", + "bat": "application/x-msdownload", + "bcpio": "application/x-bcpio", + "bdf": "application/x-font-bdf", + "bdm": "application/vnd.syncml.dm+wbxml", + "bdoc": "application/x-bdoc", + "bed": "application/vnd.realvnc.bed", + "bh2": "application/vnd.fujitsu.oasysprs", + "bin": "application/octet-stream", + "blb": "application/x-blorb", + "blorb": "application/x-blorb", + "bmi": "application/vnd.bmi", + "bmml": "application/vnd.balsamiq.bmml+xml", + "bmp": "image/x-ms-bmp", + "book": "application/vnd.framemaker", + "box": "application/vnd.previewsystems.box", + "boz": "application/x-bzip2", + "bpk": "application/octet-stream", + "bsp": "model/vnd.valve.source.compiled-map", + "btf": "image/prs.btif", + "btif": "image/prs.btif", + "buffer": "application/octet-stream", + "bz": "application/x-bzip", + "bz2": "application/x-bzip2", + "c": "text/x-c", + "c11amc": "application/vnd.cluetrust.cartomobile-config", + "c11amz": "application/vnd.cluetrust.cartomobile-config-pkg", + "c4d": "application/vnd.clonk.c4group", + "c4f": "application/vnd.clonk.c4group", + "c4g": "application/vnd.clonk.c4group", + "c4p": "application/vnd.clonk.c4group", + "c4u": "application/vnd.clonk.c4group", + "cab": "application/vnd.ms-cab-compressed", + "caf": "audio/x-caf", + "cap": "application/vnd.tcpdump.pcap", + "car": "application/vnd.curl.car", + "cat": "application/vnd.ms-pki.seccat", + "cb7": "application/x-cbr", + "cba": "application/x-cbr", + "cbr": "application/x-cbr", + "cbt": "application/x-cbr", + "cbz": "application/x-cbr", + "cc": "text/x-c", + "cco": "application/x-cocoa", + "cct": "application/x-director", + "ccxml": "application/ccxml+xml", + "cdbcmsg": "application/vnd.contact.cmsg", + "cdf": "application/x-netcdf", + "cdfx": "application/cdfx+xml", + "cdkey": "application/vnd.mediastation.cdkey", + "cdmia": "application/cdmi-capability", + "cdmic": "application/cdmi-container", + "cdmid": "application/cdmi-domain", + "cdmio": "application/cdmi-object", + "cdmiq": "application/cdmi-queue", + "cdx": "chemical/x-cdx", + "cdxml": "application/vnd.chemdraw+xml", + "cdy": "application/vnd.cinderella", + "cer": "application/pkix-cert", + "cfs": "application/x-cfs-compressed", + "cgm": "image/cgm", + "chat": "application/x-chat", + "chm": "application/vnd.ms-htmlhelp", + "chrt": "application/vnd.kde.kchart", + "cif": "chemical/x-cif", + "cii": "application/vnd.anser-web-certificate-issue-initiation", + "cil": "application/vnd.ms-artgalry", + "cjs": "application/node", + "cla": "application/vnd.claymore", + "class": "application/java-vm", + "cld": "model/vnd.cld", + "clkk": "application/vnd.crick.clicker.keyboard", + "clkp": "application/vnd.crick.clicker.palette", + "clkt": "application/vnd.crick.clicker.template", + "clkw": "application/vnd.crick.clicker.wordbank", + "clkx": "application/vnd.crick.clicker", + "clp": "application/x-msclip", + "cmc": "application/vnd.cosmocaller", + "cmdf": "chemical/x-cmdf", + "cml": "chemical/x-cml", + "cmp": "application/vnd.yellowriver-custom-menu", + "cmx": "image/x-cmx", + "cod": "application/vnd.rim.cod", + "coffee": "text/coffeescript", + "com": "application/x-msdownload", + "conf": "text/plain", + "cpio": "application/x-cpio", + "cpl": "application/cpl+xml", + "cpp": "text/x-c", + "cpt": "application/mac-compactpro", + "crd": "application/x-mscardfile", + "crl": "application/pkix-crl", + "crt": "application/x-x509-ca-cert", + "crx": "application/x-chrome-extension", + "cryptonote": "application/vnd.rig.cryptonote", + "csh": "application/x-csh", + "csl": "application/vnd.citationstyles.style+xml", + "csml": "chemical/x-csml", + "csp": "application/vnd.commonspace", + "css": "text/css", + "cst": "application/x-director", + "csv": "text/csv", + "cu": "application/cu-seeme", + "curl": "text/vnd.curl", + "cwl": "application/cwl", + "cww": "application/prs.cww", + "cxt": "application/x-director", + "cxx": "text/x-c", + "dae": "model/vnd.collada+xml", + "daf": "application/vnd.mobius.daf", + "dart": "application/vnd.dart", + "dataless": "application/vnd.fdsn.seed", + "davmount": "application/davmount+xml", + "dbf": "application/vnd.dbf", + "dbk": "application/docbook+xml", + "dcr": "application/x-director", + "dcurl": "text/vnd.curl.dcurl", + "dd2": "application/vnd.oma.dd2+xml", + "ddd": "application/vnd.fujixerox.ddd", + "ddf": "application/vnd.syncml.dmddf+xml", + "dds": "image/vnd.ms-dds", + "deb": "application/x-debian-package", + "def": "text/plain", + "deploy": "application/octet-stream", + "der": "application/x-x509-ca-cert", + "dfac": "application/vnd.dreamfactory", + "dgc": "application/x-dgc-compressed", + "dib": "image/bmp", + "dic": "text/x-c", + "dir": "application/x-director", + "dis": "application/vnd.mobius.dis", + "disposition-notification": "message/disposition-notification", + "dist": "application/octet-stream", + "distz": "application/octet-stream", + "djv": "image/vnd.djvu", + "djvu": "image/vnd.djvu", + "dll": "application/x-msdownload", + "dmg": "application/x-apple-diskimage", + "dmp": "application/vnd.tcpdump.pcap", + "dms": "application/octet-stream", + "dna": "application/vnd.dna", + "doc": "application/msword", + "docm": "application/vnd.ms-word.document.macroenabled.12", + "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "dot": "application/msword", + "dotm": "application/vnd.ms-word.template.macroenabled.12", + "dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template", + "dp": "application/vnd.osgi.dp", + "dpg": "application/vnd.dpgraph", + "dpx": "image/dpx", + "dra": "audio/vnd.dra", + "drle": "image/dicom-rle", + "dsc": "text/prs.lines.tag", + "dssc": "application/dssc+der", + "dtb": "application/x-dtbook+xml", + "dtd": "application/xml-dtd", + "dts": "audio/vnd.dts", + "dtshd": "audio/vnd.dts.hd", + "dump": "application/octet-stream", + "dvb": "video/vnd.dvb.file", + "dvi": "application/x-dvi", + "dwd": "application/atsc-dwd+xml", + "dwf": "model/vnd.dwf", + "dwg": "image/vnd.dwg", + "dxf": "image/vnd.dxf", + "dxp": "application/vnd.spotfire.dxp", + "dxr": "application/x-director", + "ear": "application/java-archive", + "ecelp4800": "audio/vnd.nuera.ecelp4800", + "ecelp7470": "audio/vnd.nuera.ecelp7470", + "ecelp9600": "audio/vnd.nuera.ecelp9600", + "ecma": "application/ecmascript", + "edm": "application/vnd.novadigm.edm", + "edx": "application/vnd.novadigm.edx", + "efif": "application/vnd.picsel", + "ei6": "application/vnd.pg.osasli", + "elc": "application/octet-stream", + "emf": "image/emf", + "eml": "message/rfc822", + "emma": "application/emma+xml", + "emotionml": "application/emotionml+xml", + "emz": "application/x-msmetafile", + "eol": "audio/vnd.digital-winds", + "eot": "application/vnd.ms-fontobject", + "eps": "application/postscript", + "epub": "application/epub+zip", + "es3": "application/vnd.eszigno3+xml", + "esa": "application/vnd.osgi.subsystem", + "esf": "application/vnd.epson.esf", + "et3": "application/vnd.eszigno3+xml", + "etx": "text/x-setext", + "eva": "application/x-eva", + "evy": "application/x-envoy", + "exe": "application/x-msdownload", + "exi": "application/exi", + "exp": "application/express", + "exr": "image/aces", + "ext": "application/vnd.novadigm.ext", + "ez": "application/andrew-inset", + "ez2": "application/vnd.ezpix-album", + "ez3": "application/vnd.ezpix-package", + "f": "text/x-fortran", + "f4v": "video/x-f4v", + "f77": "text/x-fortran", + "f90": "text/x-fortran", + "fbs": "image/vnd.fastbidsheet", + "fcdt": "application/vnd.adobe.formscentral.fcdt", + "fcs": "application/vnd.isac.fcs", + "fdf": "application/vnd.fdf", + "fdt": "application/fdt+xml", + "fe_launch": "application/vnd.denovo.fcselayout-link", + "fg5": "application/vnd.fujitsu.oasysgp", + "fgd": "application/x-director", + "fh": "image/x-freehand", + "fh4": "image/x-freehand", + "fh5": "image/x-freehand", + "fh7": "image/x-freehand", + "fhc": "image/x-freehand", + "fig": "application/x-xfig", + "fits": "image/fits", + "flac": "audio/x-flac", + "fli": "video/x-fli", + "flo": "application/vnd.micrografx.flo", + "flv": "video/x-flv", + "flw": "application/vnd.kde.kivio", + "flx": "text/vnd.fmi.flexstor", + "fly": "text/vnd.fly", + "fm": "application/vnd.framemaker", + "fnc": "application/vnd.frogans.fnc", + "fo": "application/vnd.software602.filler.form+xml", + "for": "text/x-fortran", + "fpx": "image/vnd.fpx", + "frame": "application/vnd.framemaker", + "fsc": "application/vnd.fsc.weblaunch", + "fst": "image/vnd.fst", + "ftc": "application/vnd.fluxtime.clip", + "fti": "application/vnd.anser-web-funds-transfer-initiation", + "fvt": "video/vnd.fvt", + "fxp": "application/vnd.adobe.fxp", + "fxpl": "application/vnd.adobe.fxp", + "fzs": "application/vnd.fuzzysheet", + "g2w": "application/vnd.geoplan", + "g3": "image/g3fax", + "g3w": "application/vnd.geospace", + "gac": "application/vnd.groove-account", + "gam": "application/x-tads", + "gbr": "application/rpki-ghostbusters", + "gca": "application/x-gca-compressed", + "gdl": "model/vnd.gdl", + "gdoc": "application/vnd.google-apps.document", + "ged": "text/vnd.familysearch.gedcom", + "geo": "application/vnd.dynageo", + "geojson": "application/geo+json", + "gex": "application/vnd.geometry-explorer", + "ggb": "application/vnd.geogebra.file", + "ggt": "application/vnd.geogebra.tool", + "ghf": "application/vnd.groove-help", + "gif": "image/gif", + "gim": "application/vnd.groove-identity-message", + "glb": "model/gltf-binary", + "gltf": "model/gltf+json", + "gml": "application/gml+xml", + "gmx": "application/vnd.gmx", + "gnumeric": "application/x-gnumeric", + "gph": "application/vnd.flographit", + "gpx": "application/gpx+xml", + "gqf": "application/vnd.grafeq", + "gqs": "application/vnd.grafeq", + "gram": "application/srgs", + "gramps": "application/x-gramps-xml", + "gre": "application/vnd.geometry-explorer", + "grv": "application/vnd.groove-injector", + "grxml": "application/srgs+xml", + "gsf": "application/x-font-ghostscript", + "gsheet": "application/vnd.google-apps.spreadsheet", + "gslides": "application/vnd.google-apps.presentation", + "gtar": "application/x-gtar", + "gtm": "application/vnd.groove-tool-message", + "gtw": "model/vnd.gtw", + "gv": "text/vnd.graphviz", + "gxf": "application/gxf", + "gxt": "application/vnd.geonext", + "gz": "application/gzip", + "h": "text/x-c", + "h261": "video/h261", + "h263": "video/h263", + "h264": "video/h264", + "hal": "application/vnd.hal+xml", + "hbci": "application/vnd.hbci", + "hbs": "text/x-handlebars-template", + "hdd": "application/x-virtualbox-hdd", + "hdf": "application/x-hdf", + "heic": "image/heic", + "heics": "image/heic-sequence", + "heif": "image/heif", + "heifs": "image/heif-sequence", + "hej2": "image/hej2k", + "held": "application/atsc-held+xml", + "hh": "text/x-c", + "hjson": "application/hjson", + "hlp": "application/winhlp", + "hpgl": "application/vnd.hp-hpgl", + "hpid": "application/vnd.hp-hpid", + "hps": "application/vnd.hp-hps", + "hqx": "application/mac-binhex40", + "hsj2": "image/hsj2", + "htc": "text/x-component", + "htke": "application/vnd.kenameaapp", + "htm": "text/html", + "html": "text/html", + "hvd": "application/vnd.yamaha.hv-dic", + "hvp": "application/vnd.yamaha.hv-voice", + "hvs": "application/vnd.yamaha.hv-script", + "i2g": "application/vnd.intergeo", + "icc": "application/vnd.iccprofile", + "ice": "x-conference/x-cooltalk", + "icm": "application/vnd.iccprofile", + "ico": "image/x-icon", + "ics": "text/calendar", + "ief": "image/ief", + "ifb": "text/calendar", + "ifm": "application/vnd.shana.informed.formdata", + "iges": "model/iges", + "igl": "application/vnd.igloader", + "igm": "application/vnd.insors.igm", + "igs": "model/iges", + "igx": "application/vnd.micrografx.igx", + "iif": "application/vnd.shana.informed.interchange", + "img": "application/octet-stream", + "imp": "application/vnd.accpac.simply.imp", + "ims": "application/vnd.ms-ims", + "in": "text/plain", + "ini": "text/plain", + "ink": "application/inkml+xml", + "inkml": "application/inkml+xml", + "install": "application/x-install-instructions", + "iota": "application/vnd.astraea-software.iota", + "ipfix": "application/ipfix", + "ipk": "application/vnd.shana.informed.package", + "irm": "application/vnd.ibm.rights-management", + "irp": "application/vnd.irepository.package+xml", + "iso": "application/x-iso9660-image", + "itp": "application/vnd.shana.informed.formtemplate", + "its": "application/its+xml", + "ivp": "application/vnd.immervision-ivp", + "ivu": "application/vnd.immervision-ivu", + "jad": "text/vnd.sun.j2me.app-descriptor", + "jade": "text/jade", + "jam": "application/vnd.jam", + "jar": "application/java-archive", + "jardiff": "application/x-java-archive-diff", + "java": "text/x-java-source", + "jhc": "image/jphc", + "jisp": "application/vnd.jisp", + "jls": "image/jls", + "jlt": "application/vnd.hp-jlyt", + "jng": "image/x-jng", + "jnlp": "application/x-java-jnlp-file", + "joda": "application/vnd.joost.joda-archive", + "jp2": "image/jp2", + "jpe": "image/jpeg", + "jpeg": "image/jpeg", + "jpf": "image/jpx", + "jpg": "image/jpeg", + "jpg2": "image/jp2", + "jpgm": "video/jpm", + "jpgv": "video/jpeg", + "jph": "image/jph", + "jpm": "video/jpm", + "jpx": "image/jpx", + "js": "text/javascript", + "json": "application/json", + "json5": "application/json5", + "jsonld": "application/ld+json", + "jsonml": "application/jsonml+json", + "jsx": "text/jsx", + "jt": "model/jt", + "jxr": "image/jxr", + "jxra": "image/jxra", + "jxrs": "image/jxrs", + "jxs": "image/jxs", + "jxsc": "image/jxsc", + "jxsi": "image/jxsi", + "jxss": "image/jxss", + "kar": "audio/midi", + "karbon": "application/vnd.kde.karbon", + "kdbx": "application/x-keepass2", + "key": "application/x-iwork-keynote-sffkey", + "kfo": "application/vnd.kde.kformula", + "kia": "application/vnd.kidspiration", + "kml": "application/vnd.google-earth.kml+xml", + "kmz": "application/vnd.google-earth.kmz", + "kne": "application/vnd.kinar", + "knp": "application/vnd.kinar", + "kon": "application/vnd.kde.kontour", + "kpr": "application/vnd.kde.kpresenter", + "kpt": "application/vnd.kde.kpresenter", + "kpxx": "application/vnd.ds-keypoint", + "ksp": "application/vnd.kde.kspread", + "ktr": "application/vnd.kahootz", + "ktx": "image/ktx", + "ktx2": "image/ktx2", + "ktz": "application/vnd.kahootz", + "kwd": "application/vnd.kde.kword", + "kwt": "application/vnd.kde.kword", + "lasxml": "application/vnd.las.las+xml", + "latex": "application/x-latex", + "lbd": "application/vnd.llamagraphics.life-balance.desktop", + "lbe": "application/vnd.llamagraphics.life-balance.exchange+xml", + "les": "application/vnd.hhe.lesson-player", + "less": "text/less", + "lgr": "application/lgr+xml", + "lha": "application/x-lzh-compressed", + "link66": "application/vnd.route66.link66+xml", + "list": "text/plain", + "list3820": "application/vnd.ibm.modcap", + "listafp": "application/vnd.ibm.modcap", + "litcoffee": "text/coffeescript", + "lnk": "application/x-ms-shortcut", + "log": "text/plain", + "lostxml": "application/lost+xml", + "lrf": "application/octet-stream", + "lrm": "application/vnd.ms-lrm", + "ltf": "application/vnd.frogans.ltf", + "lua": "text/x-lua", + "luac": "application/x-lua-bytecode", + "lvp": "audio/vnd.lucent.voice", + "lwp": "application/vnd.lotus-wordpro", + "lzh": "application/x-lzh-compressed", + "m13": "application/x-msmediaview", + "m14": "application/x-msmediaview", + "m1v": "video/mpeg", + "m21": "application/mp21", + "m2a": "audio/mpeg", + "m2v": "video/mpeg", + "m3a": "audio/mpeg", + "m3u": "audio/x-mpegurl", + "m3u8": "application/vnd.apple.mpegurl", + "m4a": "audio/x-m4a", + "m4p": "application/mp4", + "m4s": "video/iso.segment", + "m4u": "video/vnd.mpegurl", + "m4v": "video/x-m4v", + "ma": "application/mathematica", + "mads": "application/mads+xml", + "maei": "application/mmt-aei+xml", + "mag": "application/vnd.ecowin.chart", + "maker": "application/vnd.framemaker", + "man": "text/troff", + "manifest": "text/cache-manifest", + "map": "application/json", + "mar": "application/octet-stream", + "markdown": "text/markdown", + "mathml": "application/mathml+xml", + "mb": "application/mathematica", + "mbk": "application/vnd.mobius.mbk", + "mbox": "application/mbox", + "mc1": "application/vnd.medcalcdata", + "mcd": "application/vnd.mcd", + "mcurl": "text/vnd.curl.mcurl", + "md": "text/markdown", + "mdb": "application/x-msaccess", + "mdi": "image/vnd.ms-modi", + "mdx": "text/mdx", + "me": "text/troff", + "mesh": "model/mesh", + "meta4": "application/metalink4+xml", + "metalink": "application/metalink+xml", + "mets": "application/mets+xml", + "mfm": "application/vnd.mfmp", + "mft": "application/rpki-manifest", + "mgp": "application/vnd.osgeo.mapguide.package", + "mgz": "application/vnd.proteus.magazine", + "mid": "audio/midi", + "midi": "audio/midi", + "mie": "application/x-mie", + "mif": "application/vnd.mif", + "mime": "message/rfc822", + "mj2": "video/mj2", + "mjp2": "video/mj2", + "mjs": "text/javascript", + "mk3d": "video/x-matroska", + "mka": "audio/x-matroska", + "mkd": "text/x-markdown", + "mks": "video/x-matroska", + "mkv": "video/x-matroska", + "mlp": "application/vnd.dolby.mlp", + "mmd": "application/vnd.chipnuts.karaoke-mmd", + "mmf": "application/vnd.smaf", + "mml": "text/mathml", + "mmr": "image/vnd.fujixerox.edmics-mmr", + "mng": "video/x-mng", + "mny": "application/x-msmoney", + "mobi": "application/x-mobipocket-ebook", + "mods": "application/mods+xml", + "mov": "video/quicktime", + "movie": "video/x-sgi-movie", + "mp2": "audio/mpeg", + "mp21": "application/mp21", + "mp2a": "audio/mpeg", + "mp3": "audio/mpeg", + "mp4": "video/mp4", + "mp4a": "audio/mp4", + "mp4s": "application/mp4", + "mp4v": "video/mp4", + "mpc": "application/vnd.mophun.certificate", + "mpd": "application/dash+xml", + "mpe": "video/mpeg", + "mpeg": "video/mpeg", + "mpf": "application/media-policy-dataset+xml", + "mpg": "video/mpeg", + "mpg4": "video/mp4", + "mpga": "audio/mpeg", + "mpkg": "application/vnd.apple.installer+xml", + "mpm": "application/vnd.blueice.multipass", + "mpn": "application/vnd.mophun.application", + "mpp": "application/vnd.ms-project", + "mpt": "application/vnd.ms-project", + "mpy": "application/vnd.ibm.minipay", + "mqy": "application/vnd.mobius.mqy", + "mrc": "application/marc", + "mrcx": "application/marcxml+xml", + "ms": "text/troff", + "mscml": "application/mediaservercontrol+xml", + "mseed": "application/vnd.fdsn.mseed", + "mseq": "application/vnd.mseq", + "msf": "application/vnd.epson.msf", + "msg": "application/vnd.ms-outlook", + "msh": "model/mesh", + "msi": "application/x-msdownload", + "msix": "application/msix", + "msixbundle": "application/msixbundle", + "msl": "application/vnd.mobius.msl", + "msm": "application/octet-stream", + "msp": "application/octet-stream", + "msty": "application/vnd.muvee.style", + "mtl": "model/mtl", + "mts": "model/vnd.mts", + "mus": "application/vnd.musician", + "musd": "application/mmt-usd+xml", + "musicxml": "application/vnd.recordare.musicxml+xml", + "mvb": "application/x-msmediaview", + "mvt": "application/vnd.mapbox-vector-tile", + "mwf": "application/vnd.mfer", + "mxf": "application/mxf", + "mxl": "application/vnd.recordare.musicxml", + "mxmf": "audio/mobile-xmf", + "mxml": "application/xv+xml", + "mxs": "application/vnd.triscape.mxs", + "mxu": "video/vnd.mpegurl", + "n-gage": "application/vnd.nokia.n-gage.symbian.install", + "n3": "text/n3", + "nb": "application/mathematica", + "nbp": "application/vnd.wolfram.player", + "nc": "application/x-netcdf", + "ncx": "application/x-dtbncx+xml", + "nfo": "text/x-nfo", + "ngdat": "application/vnd.nokia.n-gage.data", + "nitf": "application/vnd.nitf", + "nlu": "application/vnd.neurolanguage.nlu", + "nml": "application/vnd.enliven", + "nnd": "application/vnd.noblenet-directory", + "nns": "application/vnd.noblenet-sealer", + "nnw": "application/vnd.noblenet-web", + "npx": "image/vnd.net-fpx", + "nq": "application/n-quads", + "nsc": "application/x-conference", + "nsf": "application/vnd.lotus-notes", + "nt": "application/n-triples", + "ntf": "application/vnd.nitf", + "numbers": "application/x-iwork-numbers-sffnumbers", + "nzb": "application/x-nzb", + "oa2": "application/vnd.fujitsu.oasys2", + "oa3": "application/vnd.fujitsu.oasys3", + "oas": "application/vnd.fujitsu.oasys", + "obd": "application/x-msbinder", + "obgx": "application/vnd.openblox.game+xml", + "obj": "model/obj", + "oda": "application/oda", + "odb": "application/vnd.oasis.opendocument.database", + "odc": "application/vnd.oasis.opendocument.chart", + "odf": "application/vnd.oasis.opendocument.formula", + "odft": "application/vnd.oasis.opendocument.formula-template", + "odg": "application/vnd.oasis.opendocument.graphics", + "odi": "application/vnd.oasis.opendocument.image", + "odm": "application/vnd.oasis.opendocument.text-master", + "odp": "application/vnd.oasis.opendocument.presentation", + "ods": "application/vnd.oasis.opendocument.spreadsheet", + "odt": "application/vnd.oasis.opendocument.text", + "oga": "audio/ogg", + "ogex": "model/vnd.opengex", + "ogg": "audio/ogg", + "ogv": "video/ogg", + "ogx": "application/ogg", + "omdoc": "application/omdoc+xml", + "onepkg": "application/onenote", + "onetmp": "application/onenote", + "onetoc": "application/onenote", + "onetoc2": "application/onenote", + "opf": "application/oebps-package+xml", + "opml": "text/x-opml", + "oprc": "application/vnd.palm", + "opus": "audio/ogg", + "org": "text/x-org", + "osf": "application/vnd.yamaha.openscoreformat", + "osfpvg": "application/vnd.yamaha.openscoreformat.osfpvg+xml", + "osm": "application/vnd.openstreetmap.data+xml", + "otc": "application/vnd.oasis.opendocument.chart-template", + "otf": "font/otf", + "otg": "application/vnd.oasis.opendocument.graphics-template", + "oth": "application/vnd.oasis.opendocument.text-web", + "oti": "application/vnd.oasis.opendocument.image-template", + "otp": "application/vnd.oasis.opendocument.presentation-template", + "ots": "application/vnd.oasis.opendocument.spreadsheet-template", + "ott": "application/vnd.oasis.opendocument.text-template", + "ova": "application/x-virtualbox-ova", + "ovf": "application/x-virtualbox-ovf", + "owl": "application/rdf+xml", + "oxps": "application/oxps", + "oxt": "application/vnd.openofficeorg.extension", + "p": "text/x-pascal", + "p10": "application/pkcs10", + "p12": "application/x-pkcs12", + "p7b": "application/x-pkcs7-certificates", + "p7c": "application/pkcs7-mime", + "p7m": "application/pkcs7-mime", + "p7r": "application/x-pkcs7-certreqresp", + "p7s": "application/pkcs7-signature", + "p8": "application/pkcs8", + "pac": "application/x-ns-proxy-autoconfig", + "pages": "application/x-iwork-pages-sffpages", + "pas": "text/x-pascal", + "paw": "application/vnd.pawaafile", + "pbd": "application/vnd.powerbuilder6", + "pbm": "image/x-portable-bitmap", + "pcap": "application/vnd.tcpdump.pcap", + "pcf": "application/x-font-pcf", + "pcl": "application/vnd.hp-pcl", + "pclxl": "application/vnd.hp-pclxl", + "pct": "image/x-pict", + "pcurl": "application/vnd.curl.pcurl", + "pcx": "image/x-pcx", + "pdb": "application/x-pilot", + "pde": "text/x-processing", + "pdf": "application/pdf", + "pem": "application/x-x509-ca-cert", + "pfa": "application/x-font-type1", + "pfb": "application/x-font-type1", + "pfm": "application/x-font-type1", + "pfr": "application/font-tdpfr", + "pfx": "application/x-pkcs12", + "pgm": "image/x-portable-graymap", + "pgn": "application/x-chess-pgn", + "pgp": "application/pgp-encrypted", + "php": "application/x-httpd-php", + "pic": "image/x-pict", + "pkg": "application/octet-stream", + "pki": "application/pkixcmp", + "pkipath": "application/pkix-pkipath", + "pkpass": "application/vnd.apple.pkpass", + "pl": "application/x-perl", + "plb": "application/vnd.3gpp.pic-bw-large", + "plc": "application/vnd.mobius.plc", + "plf": "application/vnd.pocketlearn", + "pls": "application/pls+xml", + "pm": "application/x-perl", + "pml": "application/vnd.ctc-posml", + "png": "image/png", + "pnm": "image/x-portable-anymap", + "portpkg": "application/vnd.macports.portpkg", + "pot": "application/vnd.ms-powerpoint", + "potm": "application/vnd.ms-powerpoint.template.macroenabled.12", + "potx": "application/vnd.openxmlformats-officedocument.presentationml.template", + "ppam": "application/vnd.ms-powerpoint.addin.macroenabled.12", + "ppd": "application/vnd.cups-ppd", + "ppm": "image/x-portable-pixmap", + "pps": "application/vnd.ms-powerpoint", + "ppsm": "application/vnd.ms-powerpoint.slideshow.macroenabled.12", + "ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow", + "ppt": "application/vnd.ms-powerpoint", + "pptm": "application/vnd.ms-powerpoint.presentation.macroenabled.12", + "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "pqa": "application/vnd.palm", + "prc": "model/prc", + "pre": "application/vnd.lotus-freelance", + "prf": "application/pics-rules", + "provx": "application/provenance+xml", + "ps": "application/postscript", + "psb": "application/vnd.3gpp.pic-bw-small", + "psd": "image/vnd.adobe.photoshop", + "psf": "application/x-font-linux-psf", + "pskcxml": "application/pskc+xml", + "pti": "image/prs.pti", + "ptid": "application/vnd.pvi.ptid1", + "pub": "application/x-mspublisher", + "pvb": "application/vnd.3gpp.pic-bw-var", + "pwn": "application/vnd.3m.post-it-notes", + "pya": "audio/vnd.ms-playready.media.pya", + "pyo": "model/vnd.pytha.pyox", + "pyox": "model/vnd.pytha.pyox", + "pyv": "video/vnd.ms-playready.media.pyv", + "qam": "application/vnd.epson.quickanime", + "qbo": "application/vnd.intu.qbo", + "qfx": "application/vnd.intu.qfx", + "qps": "application/vnd.publishare-delta-tree", + "qt": "video/quicktime", + "qwd": "application/vnd.quark.quarkxpress", + "qwt": "application/vnd.quark.quarkxpress", + "qxb": "application/vnd.quark.quarkxpress", + "qxd": "application/vnd.quark.quarkxpress", + "qxl": "application/vnd.quark.quarkxpress", + "qxt": "application/vnd.quark.quarkxpress", + "ra": "audio/x-realaudio", + "ram": "audio/x-pn-realaudio", + "raml": "application/raml+yaml", + "rapd": "application/route-apd+xml", + "rar": "application/x-rar-compressed", + "ras": "image/x-cmu-raster", + "rcprofile": "application/vnd.ipunplugged.rcprofile", + "rdf": "application/rdf+xml", + "rdz": "application/vnd.data-vision.rdz", + "relo": "application/p2p-overlay+xml", + "rep": "application/vnd.businessobjects", + "res": "application/x-dtbresource+xml", + "rgb": "image/x-rgb", + "rif": "application/reginfo+xml", + "rip": "audio/vnd.rip", + "ris": "application/x-research-info-systems", + "rl": "application/resource-lists+xml", + "rlc": "image/vnd.fujixerox.edmics-rlc", + "rld": "application/resource-lists-diff+xml", + "rm": "application/vnd.rn-realmedia", + "rmi": "audio/midi", + "rmp": "audio/x-pn-realaudio-plugin", + "rms": "application/vnd.jcp.javame.midlet-rms", + "rmvb": "application/vnd.rn-realmedia-vbr", + "rnc": "application/relax-ng-compact-syntax", + "rng": "application/xml", + "roa": "application/rpki-roa", + "roff": "text/troff", + "rp9": "application/vnd.cloanto.rp9", + "rpm": "application/x-redhat-package-manager", + "rpss": "application/vnd.nokia.radio-presets", + "rpst": "application/vnd.nokia.radio-preset", + "rq": "application/sparql-query", + "rs": "application/rls-services+xml", + "rsat": "application/atsc-rsat+xml", + "rsd": "application/rsd+xml", + "rsheet": "application/urc-ressheet+xml", + "rss": "application/rss+xml", + "rtf": "text/rtf", + "rtx": "text/richtext", + "run": "application/x-makeself", + "rusd": "application/route-usd+xml", + "s": "text/x-asm", + "s3m": "audio/s3m", + "saf": "application/vnd.yamaha.smaf-audio", + "sass": "text/x-sass", + "sbml": "application/sbml+xml", + "sc": "application/vnd.ibm.secure-container", + "scd": "application/x-msschedule", + "scm": "application/vnd.lotus-screencam", + "scq": "application/scvp-cv-request", + "scs": "application/scvp-cv-response", + "scss": "text/x-scss", + "scurl": "text/vnd.curl.scurl", + "sda": "application/vnd.stardivision.draw", + "sdc": "application/vnd.stardivision.calc", + "sdd": "application/vnd.stardivision.impress", + "sdkd": "application/vnd.solent.sdkm+xml", + "sdkm": "application/vnd.solent.sdkm+xml", + "sdp": "application/sdp", + "sdw": "application/vnd.stardivision.writer", + "sea": "application/x-sea", + "see": "application/vnd.seemail", + "seed": "application/vnd.fdsn.seed", + "sema": "application/vnd.sema", + "semd": "application/vnd.semd", + "semf": "application/vnd.semf", + "senmlx": "application/senml+xml", + "sensmlx": "application/sensml+xml", + "ser": "application/java-serialized-object", + "setpay": "application/set-payment-initiation", + "setreg": "application/set-registration-initiation", + "sfd-hdstx": "application/vnd.hydrostatix.sof-data", + "sfs": "application/vnd.spotfire.sfs", + "sfv": "text/x-sfv", + "sgi": "image/sgi", + "sgl": "application/vnd.stardivision.writer-global", + "sgm": "text/sgml", + "sgml": "text/sgml", + "sh": "application/x-sh", + "shar": "application/x-shar", + "shex": "text/shex", + "shf": "application/shf+xml", + "shtml": "text/html", + "sid": "image/x-mrsid-image", + "sieve": "application/sieve", + "sig": "application/pgp-signature", + "sil": "audio/silk", + "silo": "model/mesh", + "sis": "application/vnd.symbian.install", + "sisx": "application/vnd.symbian.install", + "sit": "application/x-stuffit", + "sitx": "application/x-stuffitx", + "siv": "application/sieve", + "skd": "application/vnd.koan", + "skm": "application/vnd.koan", + "skp": "application/vnd.koan", + "skt": "application/vnd.koan", + "sldm": "application/vnd.ms-powerpoint.slide.macroenabled.12", + "sldx": "application/vnd.openxmlformats-officedocument.presentationml.slide", + "slim": "text/slim", + "slm": "text/slim", + "sls": "application/route-s-tsid+xml", + "slt": "application/vnd.epson.salt", + "sm": "application/vnd.stepmania.stepchart", + "smf": "application/vnd.stardivision.math", + "smi": "application/smil+xml", + "smil": "application/smil+xml", + "smv": "video/x-smv", + "smzip": "application/vnd.stepmania.package", + "snd": "audio/basic", + "snf": "application/x-font-snf", + "so": "application/octet-stream", + "spc": "application/x-pkcs7-certificates", + "spdx": "text/spdx", + "spf": "application/vnd.yamaha.smaf-phrase", + "spl": "application/x-futuresplash", + "spot": "text/vnd.in3d.spot", + "spp": "application/scvp-vp-response", + "spq": "application/scvp-vp-request", + "spx": "audio/ogg", + "sql": "application/x-sql", + "src": "application/x-wais-source", + "srt": "application/x-subrip", + "sru": "application/sru+xml", + "srx": "application/sparql-results+xml", + "ssdl": "application/ssdl+xml", + "sse": "application/vnd.kodak-descriptor", + "ssf": "application/vnd.epson.ssf", + "ssml": "application/ssml+xml", + "st": "application/vnd.sailingtracker.track", + "stc": "application/vnd.sun.xml.calc.template", + "std": "application/vnd.sun.xml.draw.template", + "stf": "application/vnd.wt.stf", + "sti": "application/vnd.sun.xml.impress.template", + "stk": "application/hyperstudio", + "stl": "model/stl", + "stpx": "model/step+xml", + "stpxz": "model/step-xml+zip", + "stpz": "model/step+zip", + "str": "application/vnd.pg.format", + "stw": "application/vnd.sun.xml.writer.template", + "styl": "text/stylus", + "stylus": "text/stylus", + "sub": "text/vnd.dvb.subtitle", + "sus": "application/vnd.sus-calendar", + "susp": "application/vnd.sus-calendar", + "sv4cpio": "application/x-sv4cpio", + "sv4crc": "application/x-sv4crc", + "svc": "application/vnd.dvb.service", + "svd": "application/vnd.svd", + "svg": "image/svg+xml", + "svgz": "image/svg+xml", + "swa": "application/x-director", + "swf": "application/x-shockwave-flash", + "swi": "application/vnd.aristanetworks.swi", + "swidtag": "application/swid+xml", + "sxc": "application/vnd.sun.xml.calc", + "sxd": "application/vnd.sun.xml.draw", + "sxg": "application/vnd.sun.xml.writer.global", + "sxi": "application/vnd.sun.xml.impress", + "sxm": "application/vnd.sun.xml.math", + "sxw": "application/vnd.sun.xml.writer", + "t": "text/troff", + "t3": "application/x-t3vm-image", + "t38": "image/t38", + "taglet": "application/vnd.mynfc", + "tao": "application/vnd.tao.intent-module-archive", + "tap": "image/vnd.tencent.tap", + "tar": "application/x-tar", + "tcap": "application/vnd.3gpp2.tcap", + "tcl": "application/x-tcl", + "td": "application/urc-targetdesc+xml", + "teacher": "application/vnd.smart.teacher", + "tei": "application/tei+xml", + "teicorpus": "application/tei+xml", + "tex": "application/x-tex", + "texi": "application/x-texinfo", + "texinfo": "application/x-texinfo", + "text": "text/plain", + "tfi": "application/thraud+xml", + "tfm": "application/x-tex-tfm", + "tfx": "image/tiff-fx", + "tga": "image/x-tga", + "thmx": "application/vnd.ms-officetheme", + "tif": "image/tiff", + "tiff": "image/tiff", + "tk": "application/x-tcl", + "tmo": "application/vnd.tmobile-livetv", + "toml": "application/toml", + "torrent": "application/x-bittorrent", + "tpl": "application/vnd.groove-tool-template", + "tpt": "application/vnd.trid.tpt", + "tr": "text/troff", + "tra": "application/vnd.trueapp", + "trig": "application/trig", + "trm": "application/x-msterminal", + "ts": "video/mp2t", + "tsd": "application/timestamped-data", + "tsv": "text/tab-separated-values", + "ttc": "font/collection", + "ttf": "font/ttf", + "ttl": "text/turtle", + "ttml": "application/ttml+xml", + "twd": "application/vnd.simtech-mindmapper", + "twds": "application/vnd.simtech-mindmapper", + "txd": "application/vnd.genomatix.tuxedo", + "txf": "application/vnd.mobius.txf", + "txt": "text/plain", + "u32": "application/x-authorware-bin", + "u3d": "model/u3d", + "u8dsn": "message/global-delivery-status", + "u8hdr": "message/global-headers", + "u8mdn": "message/global-disposition-notification", + "u8msg": "message/global", + "ubj": "application/ubjson", + "udeb": "application/x-debian-package", + "ufd": "application/vnd.ufdl", + "ufdl": "application/vnd.ufdl", + "ulx": "application/x-glulx", + "umj": "application/vnd.umajin", + "unityweb": "application/vnd.unity", + "uo": "application/vnd.uoml+xml", + "uoml": "application/vnd.uoml+xml", + "uri": "text/uri-list", + "uris": "text/uri-list", + "urls": "text/uri-list", + "usda": "model/vnd.usda", + "usdz": "model/vnd.usdz+zip", + "ustar": "application/x-ustar", + "utz": "application/vnd.uiq.theme", + "uu": "text/x-uuencode", + "uva": "audio/vnd.dece.audio", + "uvd": "application/vnd.dece.data", + "uvf": "application/vnd.dece.data", + "uvg": "image/vnd.dece.graphic", + "uvh": "video/vnd.dece.hd", + "uvi": "image/vnd.dece.graphic", + "uvm": "video/vnd.dece.mobile", + "uvp": "video/vnd.dece.pd", + "uvs": "video/vnd.dece.sd", + "uvt": "application/vnd.dece.ttml+xml", + "uvu": "video/vnd.uvvu.mp4", + "uvv": "video/vnd.dece.video", + "uvva": "audio/vnd.dece.audio", + "uvvd": "application/vnd.dece.data", + "uvvf": "application/vnd.dece.data", + "uvvg": "image/vnd.dece.graphic", + "uvvh": "video/vnd.dece.hd", + "uvvi": "image/vnd.dece.graphic", + "uvvm": "video/vnd.dece.mobile", + "uvvp": "video/vnd.dece.pd", + "uvvs": "video/vnd.dece.sd", + "uvvt": "application/vnd.dece.ttml+xml", + "uvvu": "video/vnd.uvvu.mp4", + "uvvv": "video/vnd.dece.video", + "uvvx": "application/vnd.dece.unspecified", + "uvvz": "application/vnd.dece.zip", + "uvx": "application/vnd.dece.unspecified", + "uvz": "application/vnd.dece.zip", + "vbox": "application/x-virtualbox-vbox", + "vbox-extpack": "application/x-virtualbox-vbox-extpack", + "vcard": "text/vcard", + "vcd": "application/x-cdlink", + "vcf": "text/x-vcard", + "vcg": "application/vnd.groove-vcard", + "vcs": "text/x-vcalendar", + "vcx": "application/vnd.vcx", + "vdi": "application/x-virtualbox-vdi", + "vds": "model/vnd.sap.vds", + "vhd": "application/x-virtualbox-vhd", + "vis": "application/vnd.visionary", + "viv": "video/vnd.vivo", + "vmdk": "application/x-virtualbox-vmdk", + "vob": "video/x-ms-vob", + "vor": "application/vnd.stardivision.writer", + "vox": "application/x-authorware-bin", + "vrml": "model/vrml", + "vsd": "application/vnd.visio", + "vsf": "application/vnd.vsf", + "vss": "application/vnd.visio", + "vst": "application/vnd.visio", + "vsw": "application/vnd.visio", + "vtf": "image/vnd.valve.source.texture", + "vtt": "text/vtt", + "vtu": "model/vnd.vtu", + "vxml": "application/voicexml+xml", + "w3d": "application/x-director", + "wad": "application/x-doom", + "wadl": "application/vnd.sun.wadl+xml", + "war": "application/java-archive", + "wasm": "application/wasm", + "wav": "audio/x-wav", + "wax": "audio/x-ms-wax", + "wbmp": "image/vnd.wap.wbmp", + "wbs": "application/vnd.criticaltools.wbs+xml", + "wbxml": "application/vnd.wap.wbxml", + "wcm": "application/vnd.ms-works", + "wdb": "application/vnd.ms-works", + "wdp": "image/vnd.ms-photo", + "weba": "audio/webm", + "webapp": "application/x-web-app-manifest+json", + "webm": "video/webm", + "webmanifest": "application/manifest+json", + "webp": "image/webp", + "wg": "application/vnd.pmi.widget", + "wgsl": "text/wgsl", + "wgt": "application/widget", + "wif": "application/watcherinfo+xml", + "wks": "application/vnd.ms-works", + "wm": "video/x-ms-wm", + "wma": "audio/x-ms-wma", + "wmd": "application/x-ms-wmd", + "wmf": "image/wmf", + "wml": "text/vnd.wap.wml", + "wmlc": "application/vnd.wap.wmlc", + "wmls": "text/vnd.wap.wmlscript", + "wmlsc": "application/vnd.wap.wmlscriptc", + "wmv": "video/x-ms-wmv", + "wmx": "video/x-ms-wmx", + "wmz": "application/x-msmetafile", + "woff": "font/woff", + "woff2": "font/woff2", + "wpd": "application/vnd.wordperfect", + "wpl": "application/vnd.ms-wpl", + "wps": "application/vnd.ms-works", + "wqd": "application/vnd.wqd", + "wri": "application/x-mswrite", + "wrl": "model/vrml", + "wsc": "message/vnd.wfa.wsc", + "wsdl": "application/wsdl+xml", + "wspolicy": "application/wspolicy+xml", + "wtb": "application/vnd.webturbo", + "wvx": "video/x-ms-wvx", + "x32": "application/x-authorware-bin", + "x3d": "model/x3d+xml", + "x3db": "model/x3d+fastinfoset", + "x3dbz": "model/x3d+binary", + "x3dv": "model/x3d-vrml", + "x3dvz": "model/x3d+vrml", + "x3dz": "model/x3d+xml", + "x_b": "model/vnd.parasolid.transmit.binary", + "x_t": "model/vnd.parasolid.transmit.text", + "xaml": "application/xaml+xml", + "xap": "application/x-silverlight-app", + "xar": "application/vnd.xara", + "xav": "application/xcap-att+xml", + "xbap": "application/x-ms-xbap", + "xbd": "application/vnd.fujixerox.docuworks.binder", + "xbm": "image/x-xbitmap", + "xca": "application/xcap-caps+xml", + "xcs": "application/calendar+xml", + "xdf": "application/xcap-diff+xml", + "xdm": "application/vnd.syncml.dm+xml", + "xdp": "application/vnd.adobe.xdp+xml", + "xdssc": "application/dssc+xml", + "xdw": "application/vnd.fujixerox.docuworks", + "xel": "application/xcap-el+xml", + "xenc": "application/xenc+xml", + "xer": "application/patch-ops-error+xml", + "xfdf": "application/xfdf", + "xfdl": "application/vnd.xfdl", + "xht": "application/xhtml+xml", + "xhtm": "application/vnd.pwg-xhtml-print+xml", + "xhtml": "application/xhtml+xml", + "xhvml": "application/xv+xml", + "xif": "image/vnd.xiff", + "xla": "application/vnd.ms-excel", + "xlam": "application/vnd.ms-excel.addin.macroenabled.12", + "xlc": "application/vnd.ms-excel", + "xlf": "application/xliff+xml", + "xlm": "application/vnd.ms-excel", + "xls": "application/vnd.ms-excel", + "xlsb": "application/vnd.ms-excel.sheet.binary.macroenabled.12", + "xlsm": "application/vnd.ms-excel.sheet.macroenabled.12", + "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "xlt": "application/vnd.ms-excel", + "xltm": "application/vnd.ms-excel.template.macroenabled.12", + "xltx": "application/vnd.openxmlformats-officedocument.spreadsheetml.template", + "xlw": "application/vnd.ms-excel", + "xm": "audio/xm", + "xml": "text/xml", + "xns": "application/xcap-ns+xml", + "xo": "application/vnd.olpc-sugar", + "xop": "application/xop+xml", + "xpi": "application/x-xpinstall", + "xpl": "application/xproc+xml", + "xpm": "image/x-xpixmap", + "xpr": "application/vnd.is-xpr", + "xps": "application/vnd.ms-xpsdocument", + "xpw": "application/vnd.intercon.formnet", + "xpx": "application/vnd.intercon.formnet", + "xsd": "application/xml", + "xsf": "application/prs.xsf+xml", + "xsl": "application/xslt+xml", + "xslt": "application/xslt+xml", + "xsm": "application/vnd.syncml+xml", + "xspf": "application/xspf+xml", + "xul": "application/vnd.mozilla.xul+xml", + "xvm": "application/xv+xml", + "xvml": "application/xv+xml", + "xwd": "image/x-xwindowdump", + "xyz": "chemical/x-xyz", + "xz": "application/x-xz", + "yaml": "text/yaml", + "yang": "application/yang", + "yin": "application/yin+xml", + "yml": "text/yaml", + "ymp": "text/x-suse-ymp", + "z1": "application/x-zmachine", + "z2": "application/x-zmachine", + "z3": "application/x-zmachine", + "z4": "application/x-zmachine", + "z5": "application/x-zmachine", + "z6": "application/x-zmachine", + "z7": "application/x-zmachine", + "z8": "application/x-zmachine", + "zaz": "application/vnd.zzazz.deck+xml", + "zip": "application/zip", + "zir": "application/vnd.zul", + "zirz": "application/vnd.zul", + "zmm": "application/vnd.handheld-entertainment+xml", +} diff --git a/vendor/codeberg.org/gruf/go-mimetypes/mime.go b/vendor/codeberg.org/gruf/go-mimetypes/mime.go new file mode 100644 index 000000000..028092da6 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-mimetypes/mime.go @@ -0,0 +1,47 @@ +package mimetypes + +import "path" + +// PreferredExts defines preferred file +// extensions for input mime types (as there +// can be multiple extensions per mime type). +var PreferredExts = map[string]string{ + MimeTypes["mp3"]: "mp3", // audio/mpeg + MimeTypes["mpeg"]: "mpeg", // video/mpeg +} + +// GetForFilename returns mimetype for given filename. +func GetForFilename(filename string) (string, bool) { + ext := path.Ext(filename) + if len(ext) < 1 { + return "", false + } + mime, ok := MimeTypes[ext[1:]] + return mime, ok +} + +// GetFileExt returns the file extension to use for mimetype. Relying first upon +// the 'PreferredExts' map. It simply returns the first match there may multiple. +func GetFileExt(mimeType string) (string, bool) { + ext, ok := PreferredExts[mimeType] + if ok { + return ext, true + } + for ext, mime := range MimeTypes { + if mime == mimeType { + return ext, true + } + } + return "", false +} + +// GetFileExts returns known file extensions used for mimetype. +func GetFileExts(mimeType string) []string { + var exts []string + for ext, mime := range MimeTypes { + if mime == mimeType { + exts = append(exts, ext) + } + } + return exts +} diff --git a/vendor/codeberg.org/gruf/go-storage/memory/memory.go b/vendor/codeberg.org/gruf/go-storage/memory/memory.go index 55728b827..db3199338 100644 --- a/vendor/codeberg.org/gruf/go-storage/memory/memory.go +++ b/vendor/codeberg.org/gruf/go-storage/memory/memory.go @@ -7,7 +7,6 @@ import ( "strings" "sync" - "codeberg.org/gruf/go-iotools" "codeberg.org/gruf/go-storage" "codeberg.org/gruf/go-storage/internal" @@ -93,7 +92,7 @@ func (st *MemoryStorage) ReadStream(ctx context.Context, key string) (io.ReadClo // Wrap in readcloser. r := bytes.NewReader(b) - return iotools.NopReadCloser(r), nil + return io.NopCloser(r), nil } // WriteBytes: implements Storage.WriteBytes(). diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/README.md b/vendor/codeberg.org/superseriousbusiness/exif-terminator/README.md deleted file mode 100644 index ddb97fbb6..000000000 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# exif-terminator - -`exif-terminator` removes exif data from images (jpeg and png currently supported) in a streaming manner. All you need to do is provide a reader of the image in, and exif-terminator will provide a reader of the image out. - -Hasta la vista, baby! - -```text - .,lddxococ. - ..',lxO0Oo;'. - . .. .,coodO0klc:. - .,. ..','. .. .,..'. .':llxKXk' - .;c:cc;;,... .''.,l:cc. .....:l:,,:oo:.. - .,:ll'. .,;cox0OxOKKXX0kOOxlcld0X0d;,,,'. - .:xkl. .':cdKNWWWWMMMMMMMMMMWWNXK0KWNd. - .coxo,..:ollk0KKXNWMMMMMMMMMMWWXXXOoOM0; - ,oc,. .;cloxOKXXWWMMMMMMMMMMMWNXk;;OWO' - . ..;cdOKXNNWWMMMMMMMMMMMMWO,,ONO' - ...... ....;okOO000XWWMMMMMMMMMWXx;,ONNx. -.;c;. .:l'ckl. ..';looooolldolloooodolcc:;'.;oo:. -.oxl. ;:..OO. .. .. .,' .;. -.oko. .cc.'Ok. .:; .:,..';. -.cdc. .;;lc.,Ox. . .',,'..','. .dN0; .. .c:,,':. -.:oc. ,dxkl.,0x. . .. . .oNMMKc.. ...:l. -.:o:. cKXKl.,Ox. .. .lKWMMMXo,. ...''. -.:l; c0KKo.,0x. ...........';:lk0OKNNXKkl,..,;cxd' -.::' ;k00l.;0d. .. .,cloooddddxxddol;:ddloxdc,:odOWNc -.;,. ,ONKc.;0d. 'l,.. .:clllllllokKOl::cllclkKx'.lolxx' -.,. '0W0:.;0d. .:l,. .,:ccc:::oOXNXOkxdook0NWNx,,;c;. -... .kX0c.;0d. .loc' .,::;;;;lk0kddoooooddooO0o',ld; -.. .oOkk:cKd. .... .;:,',;cxK0o::ldkOkkOkxod:';oKx. -.. :dlOolKO, '::'.';:oOK0xdddoollooxOx::ccOx. -.. ';:o,.xKo. .,;'...';lddolooodkkkdol:,::lc. -.. ...:..oOl. ........';:codxxOXKKKk;':;:kl -.. .,..lOc. .. ....,codxkxxxxxo:,,;lKO. .,;'.. -... .. ck: ';,'. .;:cllloc,;;;colOK; .;odxxoc;. -...,.... . :x; .;:cc;'. .,;::c:'..,kXk:xNc .':oook00x:. - . cKx. .'.. ':clllc,...'';:::cc:;.,kOo:xNx. .'codddoox - .. ,xxl;',col:;. .:cccccc;;;:lxkkOOkdc,,lolcxWO' ;kNKc.' - .,. .c' ':dkO0O; .. .;ccccccc:::cldxkxoll:;oolcdN0:.. .xWNk; - .:' .c',xXNKkOXo .,. .,:cccccllc::lloooolc:;lo:;oXKc,::. .kWWX - ,' .cONMWMWkco, ', .';::ccclolc:llolollcccodo;:KXl..cl,. ;KWN - '. .xWWWWMKc;; ....;' ',;::::coolclloooollc:,:o;;0Xx, .,:;... ,0Ko - . ,kKNWWXd,cdd0NXKk:,;;;'';::::coollllllllllc;;ccl0Nkc. ..';loOx' - 'lxXWMXOOXNMMMMWWNNNWXkc;;;;;:cllccccccccc::lllkNWXd,. .cxO0Ol' - ,xKNWWXkkXWM0dxKNWWWMWNX0OOkl;;:c::cccc:,...:oONMMXOo;. :kOkOkl; - .;,;:;...,::. .;lokXKKNMMMWNOc,;;;,::;'...lOKNWNKkol:,..cKdcO0do - .:;... .. .,:okO0KNN0:.',,''''. ':xNMWKkxxOKXd,.cNk,:l:o -``` - -## Why? - -Exif removal is a pain in the arse. Most other libraries seem to parse the whole image into memory, then remove the exif data, then encode the image again. - -`exif-terminator` differs in that it removes exif data *while scanning through the image bytes*, and it doesn't do any reencoding of the image. Bytes of exif data are simply all set to 0, and the image data is piped back out again into the returned reader. - -The only exception is orientation data: if an image contains orientation data, this and only this data will be preserved since it's *actually useful*. - -## Example - -You can run the following example with `go run ./example/main.go`: - -```go -package main - -import ( - "io" - "os" - - terminator "codeberg.org/superseriousbusiness/exif-terminator" -) - -func main() { - // open a file - sloth, err := os.Open("./images/sloth.jpg") - if err != nil { - panic(err) - } - defer sloth.Close() - - // get the length of the file - stat, err := sloth.Stat() - if err != nil { - panic(err) - } - - // terminate! - out, err := terminator.Terminate(sloth, int(stat.Size()), "jpeg") - if err != nil { - panic(err) - } - - // read the bytes from the reader - b, err := io.ReadAll(out) - if err != nil { - panic(err) - } - - // save the file somewhere - if err := os.WriteFile("./images/sloth-clean.jpg", b, 0666); err != nil { - panic(err) - } -} -``` - -## Credits - -### Libraries - -`exif-terminator` borrows heavily from the two [`dsoprea`](https://github.com/dsoprea) libraries credited below. In fact, it's basically a hack on top of those libraries. Thanks `dsoprea`! - -- [dsoprea/go-exif](https://github.com/dsoprea/go-exif): exif header reconstruction. [MIT License](https://spdx.org/licenses/MIT.html). -- [dsoprea/go-jpeg-image-structure](https://github.com/dsoprea/go-jpeg-image-structure): jpeg structure parsing. [MIT License](https://spdx.org/licenses/MIT.html). -- [dsoprea/go-png-image-structure](https://github.com/dsoprea/go-png-image-structure): png structure parsing. [MIT License](https://spdx.org/licenses/MIT.html). -- [stretchr/testify](https://github.com/stretchr/testify); test framework. [MIT License](https://spdx.org/licenses/MIT.html). - -## License - - - -`exif-terminator` is free software, licensed under the [GNU AGPL v3 LICENSE](LICENSE). - -Copyright (C) 2022-2024 SuperSeriousBusiness. diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/jpeg.go b/vendor/codeberg.org/superseriousbusiness/exif-terminator/jpeg.go deleted file mode 100644 index 576c4e430..000000000 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/jpeg.go +++ /dev/null @@ -1,295 +0,0 @@ -/* - exif-terminator - Copyright (C) 2022 SuperSeriousBusiness admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package terminator - -import ( - "bytes" - "encoding/binary" - "fmt" - "io" - - exif "github.com/dsoprea/go-exif/v3" - jpegstructure "github.com/superseriousbusiness/go-jpeg-image-structure/v2" -) - -var markerLen = map[byte]int{ - 0x00: 0, - 0x01: 0, - 0xd0: 0, - 0xd1: 0, - 0xd2: 0, - 0xd3: 0, - 0xd4: 0, - 0xd5: 0, - 0xd6: 0, - 0xd7: 0, - 0xd8: 0, - 0xd9: 0, - 0xda: 0, - - // J2C - 0x30: 0, - 0x31: 0, - 0x32: 0, - 0x33: 0, - 0x34: 0, - 0x35: 0, - 0x36: 0, - 0x37: 0, - 0x38: 0, - 0x39: 0, - 0x3a: 0, - 0x3b: 0, - 0x3c: 0, - 0x3d: 0, - 0x3e: 0, - 0x3f: 0, - 0x4f: 0, - 0x92: 0, - 0x93: 0, - - // J2C extensions - 0x74: 4, - 0x75: 4, - 0x77: 4, -} - -type jpegVisitor struct { - js *jpegstructure.JpegSplitter - writer io.Writer - expectedFileSize int - writtenTotalBytes int -} - -// HandleSegment satisfies the visitor interface{} of the jpegstructure library. -// -// We don't really care about many of the parameters, since all we're interested -// in here is the very last segment that was scanned. -func (v *jpegVisitor) HandleSegment(segmentMarker byte, _ string, _ int, _ bool) error { - // get the most recent segment scanned (ie., last in the segments list) - segmentList := v.js.Segments() - segments := segmentList.Segments() - mostRecentSegment := segments[len(segments)-1] - - // check if we've written the expected number of bytes by EOI - if segmentMarker == jpegstructure.MARKER_EOI { - // take account of the last 2 bytes taken up by the EOI - eoiLength := 2 - - // this is the total file size we will - // have written including the EOI - willHaveWritten := v.writtenTotalBytes + eoiLength - - if willHaveWritten < v.expectedFileSize { - // if we won't have written enough, - // pad the final segment before EOI - // so that we meet expected file size - missingBytes := make([]byte, v.expectedFileSize-willHaveWritten) - if _, err := v.writer.Write(missingBytes); err != nil { - return err - } - } - } - - // process the segment - return v.writeSegment(mostRecentSegment) -} - -func (v *jpegVisitor) writeSegment(s *jpegstructure.Segment) error { - var writtenSegmentData int - w := v.writer - - defer func() { - // whatever happens, when we finished then evict data from the segment; - // once we've written it we don't want it in memory anymore - s.Data = s.Data[:0] - }() - - // The scan-data will have a marker-ID of (0) because it doesn't have a marker-ID or length. - if s.MarkerId != 0 { - markerIDWritten, err := w.Write([]byte{0xff, s.MarkerId}) - if err != nil { - return err - } - writtenSegmentData += markerIDWritten - - sizeLen, found := markerLen[s.MarkerId] - if !found || sizeLen == 2 { - sizeLen = 2 - l := uint16(len(s.Data) + sizeLen) - - if err := binary.Write(w, binary.BigEndian, &l); err != nil { - return err - } - - writtenSegmentData += 2 - } else if sizeLen == 4 { - l := uint32(len(s.Data) + sizeLen) - - if err := binary.Write(w, binary.BigEndian, &l); err != nil { - return err - } - - writtenSegmentData += 4 - } else if sizeLen != 0 { - return fmt.Errorf("not a supported marker-size: MARKER-ID=(0x%02x) MARKER-SIZE-LEN=(%d)", s.MarkerId, sizeLen) - } - } - - if !s.IsExif() { - // if this isn't exif data just copy it over and bail - writtenNormalData, err := w.Write(s.Data) - if err != nil { - return err - } - - writtenSegmentData += writtenNormalData - v.writtenTotalBytes += writtenSegmentData - return nil - } - - ifd, _, err := s.Exif() - if err != nil { - return err - } - - // amount of bytes we've writtenExifData into the exif body, we'll update this as we go - var writtenExifData int - - if orientationEntries, err := ifd.FindTagWithName("Orientation"); err == nil && len(orientationEntries) == 1 { - // If we have an orientation entry, we don't want to completely obliterate the exif data. - // Instead, we want to surgically obliterate everything *except* the orientation tag, so - // that the image will still be rotated correctly when shown in client applications etc. - // - // To accomplish this, we're going to extract just the bytes that we need and write them - // in according to the exif specification, then fill in the rest of the space with empty - // bytes. - // - // First we need to write the exif prefix for this segment. - // - // Then we write the exif header which contains the byte order and offset of the first ifd. - // - // Then we write the ifd0 entry which contains the orientation data. - // - // After that we just fill. - - newExifData := &bytes.Buffer{} - byteOrder := ifd.ByteOrder() - - // 1. Write exif prefix. - // https://www.ozhiker.com/electronics/pjmt/jpeg_info/app_segments.html - prefix := []byte{'E', 'x', 'i', 'f', 0, 0} - if err := binary.Write(newExifData, byteOrder, &prefix); err != nil { - return err - } - writtenExifData += len(prefix) - - // 2. Write exif header, taking the existing byte order. - exifHeader, err := exif.BuildExifHeader(byteOrder, exif.ExifDefaultFirstIfdOffset) - if err != nil { - return err - } - hWritten, err := newExifData.Write(exifHeader) - if err != nil { - return err - } - writtenExifData += hWritten - - // 3. Write in the new ifd - // - // An ifd with one orientation entry is structured like this: - // 2 bytes: the number of entries in the ifd uint16(1) - // 2 bytes: the tag id uint16(274) - // 2 bytes: the tag type uint16(3) - // 4 bytes: the tag count uint32(1) - // 4 bytes: the tag value offset: uint32(one of the below with padding on the end) - // 1 = Horizontal (normal) - // 2 = Mirror horizontal - // 3 = Rotate 180 - // 4 = Mirror vertical - // 5 = Mirror horizontal and rotate 270 CW - // 6 = Rotate 90 CW - // 7 = Mirror horizontal and rotate 90 CW - // 8 = Rotate 270 CW - // - // see https://web.archive.org/web/20190624045241if_/http://www.cipa.jp:80/std/documents/e/DC-008-Translation-2019-E.pdf - p24-25 - orientationEntry := orientationEntries[0] - - ifdCount := uint16(1) // we're only adding one entry into the ifd - if err := binary.Write(newExifData, byteOrder, &ifdCount); err != nil { - return err - } - writtenExifData += 2 - - tagID := orientationEntry.TagId() - if err := binary.Write(newExifData, byteOrder, &tagID); err != nil { - return err - } - writtenExifData += 2 - - tagType := uint16(orientationEntry.TagType()) - if err := binary.Write(newExifData, byteOrder, &tagType); err != nil { - return err - } - writtenExifData += 2 - - tagCount := orientationEntry.UnitCount() - if err := binary.Write(newExifData, byteOrder, &tagCount); err != nil { - return err - } - writtenExifData += 4 - - valueOffset, err := orientationEntry.GetRawBytes() - if err != nil { - return err - } - - vWritten, err := newExifData.Write(valueOffset) - if err != nil { - return err - } - writtenExifData += vWritten - - valuePad := make([]byte, 4-vWritten) - pWritten, err := newExifData.Write(valuePad) - if err != nil { - return err - } - writtenExifData += pWritten - - // write all the new data into the writer from the segment - writtenNewExifData, err := io.Copy(w, newExifData) - if err != nil { - return err - } - - writtenSegmentData += int(writtenNewExifData) - } - - // fill in any remaining exif body with blank bytes - blank := make([]byte, len(s.Data)-writtenExifData) - writtenPadding, err := w.Write(blank) - if err != nil { - return err - } - - writtenSegmentData += writtenPadding - v.writtenTotalBytes += writtenSegmentData - return nil -} diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/png.go b/vendor/codeberg.org/superseriousbusiness/exif-terminator/png.go deleted file mode 100644 index 774ec0ed6..000000000 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/png.go +++ /dev/null @@ -1,93 +0,0 @@ -/* - exif-terminator - Copyright (C) 2022 SuperSeriousBusiness admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package terminator - -import ( - "io" - - pngstructure "github.com/superseriousbusiness/go-png-image-structure/v2" -) - -type pngVisitor struct { - ps *pngstructure.PngSplitter - writer io.Writer - lastWrittenChunk int -} - -func (v *pngVisitor) split(data []byte, atEOF bool) (int, []byte, error) { - // execute the ps split function to read in data - advance, token, err := v.ps.Split(data, atEOF) - if err != nil { - return advance, token, err - } - - // if we haven't written anything at all yet, then write the png header back into the writer first - if v.lastWrittenChunk == -1 { - if _, err := v.writer.Write(pngstructure.PngSignature[:]); err != nil { - return advance, token, err - } - } - - // Check if the splitter now has - // any new chunks in it for us. - chunkSlice, err := v.ps.Chunks() - if err != nil { - return advance, token, err - } - - // Write each chunk by passing it - // through our custom write func, - // which strips out exif and fixes - // the CRC of each chunk. - chunks := chunkSlice.Chunks() - for i, chunk := range chunks { - if i <= v.lastWrittenChunk { - // Skip already - // written chunks. - continue - } - - // Write this new chunk. - if err := v.writeChunk(chunk); err != nil { - return advance, token, err - } - v.lastWrittenChunk = i - - // Zero data; here you - // go garbage collector. - chunk.Data = nil - } - - return advance, token, err -} - -func (v *pngVisitor) writeChunk(chunk *pngstructure.Chunk) error { - if chunk.Type == pngstructure.EXifChunkType { - // Replace exif data - // with zero bytes. - clear(chunk.Data) - } - - // Fix CRC of each chunk. - chunk.UpdateCrc32() - - // finally, write chunk to writer. - _, err := chunk.WriteTo(v.writer) - return err -} diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/terminator.go b/vendor/codeberg.org/superseriousbusiness/exif-terminator/terminator.go deleted file mode 100644 index 7dd3d9ad7..000000000 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/terminator.go +++ /dev/null @@ -1,158 +0,0 @@ -/* - exif-terminator - Copyright (C) 2022 SuperSeriousBusiness admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package terminator - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - - jpegstructure "github.com/superseriousbusiness/go-jpeg-image-structure/v2" - pngstructure "github.com/superseriousbusiness/go-png-image-structure/v2" -) - -func Terminate(in io.Reader, fileSize int, mediaType string) (io.Reader, error) { - // To avoid keeping too much stuff - // in memory we want to pipe data - // directly to the reader. - pipeReader, pipeWriter := io.Pipe() - - // We don't know ahead of time how long - // segments might be: they could be as - // large as the file itself, so we need - // a buffer with generous overhead. - scanner := bufio.NewScanner(in) - scanner.Buffer([]byte{}, fileSize) - - var err error - switch mediaType { - case "image/jpeg", "jpeg", "jpg": - err = terminateJpeg(scanner, pipeWriter, fileSize) - - case "image/webp", "webp": - err = terminateWebp(scanner, pipeWriter) - - case "image/png", "png": - // For pngs we need to skip the header bytes, so read - // them in and check we're really dealing with a png. - header := make([]byte, len(pngstructure.PngSignature)) - if _, headerError := in.Read(header); headerError != nil { - err = headerError - break - } - - if !bytes.Equal(header, pngstructure.PngSignature[:]) { - err = errors.New("could not decode png: invalid header") - break - } - - err = terminatePng(scanner, pipeWriter) - default: - err = fmt.Errorf("mediaType %s cannot be processed", mediaType) - } - - return pipeReader, err -} - -func terminateJpeg(scanner *bufio.Scanner, writer *io.PipeWriter, expectedFileSize int) error { - v := &jpegVisitor{ - writer: writer, - expectedFileSize: expectedFileSize, - } - - // Provide the visitor to the splitter so - // that it triggers on every section scan. - js := jpegstructure.NewJpegSplitter(v) - - // The visitor also needs to read back the - // list of segments: for this it needs to - // know what jpeg splitter it's attached to, - // so give it a pointer to the splitter. - v.js = js - - // Jpeg visitor's 'split' function - // satisfies bufio.SplitFunc{}. - scanner.Split(js.Split) - - go scanAndClose(scanner, writer) - return nil -} - -func terminateWebp(scanner *bufio.Scanner, writer *io.PipeWriter) error { - v := &webpVisitor{ - writer: writer, - } - - // Webp visitor's 'split' function - // satisfies bufio.SplitFunc{}. - scanner.Split(v.split) - - go scanAndClose(scanner, writer) - return nil -} - -func terminatePng(scanner *bufio.Scanner, writer *io.PipeWriter) error { - ps := pngstructure.NewPngSplitter() - - // Don't bother checking CRC; - // we're overwriting it anyway. - ps.DoCheckCrc(false) - - v := &pngVisitor{ - ps: ps, - writer: writer, - lastWrittenChunk: -1, - } - - // Png visitor's 'split' function - // satisfies bufio.SplitFunc{}. - scanner.Split(v.split) - - go scanAndClose(scanner, writer) - return nil -} - -// scanAndClose scans through the given scanner until there's -// nothing left to scan, and then closes the writer so that the -// reader on the other side of the pipe knows that we're done. -// -// Any error encountered when scanning will be logged by terminator. -// -// Due to the nature of io.Pipe, writing won't actually work -// until the pipeReader starts being read by the caller, which -// is why this function should always be called asynchronously. -func scanAndClose(scanner *bufio.Scanner, writer *io.PipeWriter) { - var err error - - defer func() { - // Always close writer, using returned - // scanner error (if any). If err is nil - // then the standard io.EOF will be used. - // (this will not overwrite existing). - writer.CloseWithError(err) - }() - - for scanner.Scan() { - } - - // Set error on return. - err = scanner.Err() -} diff --git a/vendor/codeberg.org/superseriousbusiness/exif-terminator/webp.go b/vendor/codeberg.org/superseriousbusiness/exif-terminator/webp.go deleted file mode 100644 index 392c4871d..000000000 --- a/vendor/codeberg.org/superseriousbusiness/exif-terminator/webp.go +++ /dev/null @@ -1,101 +0,0 @@ -/* - exif-terminator - Copyright (C) 2022 SuperSeriousBusiness admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package terminator - -import ( - "encoding/binary" - "errors" - "io" -) - -const ( - riffHeaderSize = 4 * 3 -) - -var ( - riffHeader = [4]byte{'R', 'I', 'F', 'F'} - webpHeader = [4]byte{'W', 'E', 'B', 'P'} - exifFourcc = [4]byte{'E', 'X', 'I', 'F'} - xmpFourcc = [4]byte{'X', 'M', 'P', ' '} - - errNoRiffHeader = errors.New("no RIFF header") - errNoWebpHeader = errors.New("not a WEBP file") -) - -type webpVisitor struct { - writer io.Writer - doneHeader bool -} - -func fourCC(b []byte) [4]byte { - return [4]byte{b[0], b[1], b[2], b[3]} -} - -func (v *webpVisitor) split(data []byte, atEOF bool) (advance int, token []byte, err error) { - // parse/write the header first - if !v.doneHeader { - if len(data) < riffHeaderSize { - // need the full header - return - } - if fourCC(data) != riffHeader { - err = errNoRiffHeader - return - } - if fourCC(data[8:]) != webpHeader { - err = errNoWebpHeader - return - } - if _, err = v.writer.Write(data[:riffHeaderSize]); err != nil { - return - } - advance += riffHeaderSize - data = data[riffHeaderSize:] - v.doneHeader = true - } - - // need enough for fourcc and size - if len(data) < 8 { - return - } - size := int64(binary.LittleEndian.Uint32(data[4:])) - if (size & 1) != 0 { - // odd chunk size - extra padding byte - size++ - } - // wait until there is enough - if int64(len(data)-8) < size { - return - } - - fourcc := fourCC(data) - rawChunkData := data[8 : 8+size] - if fourcc == exifFourcc || fourcc == xmpFourcc { - // replace exif/xmp with blank - rawChunkData = make([]byte, size) - } - - if _, err = v.writer.Write(data[:8]); err == nil { - if _, err = v.writer.Write(rawChunkData); err == nil { - advance += 8 + int(size) - } - } - - return -} |