A Flysystem proxy adapter that enables compression and encryption of files and streams on the fly

Overview

Slam / flysystem-compress-and-encrypt-proxy

Latest Stable Version Downloads Integrate Code Coverage Type Coverage Infection MSI

Compress and Encrypt files and streams before saving them to the final Flysystem destination.

Installation

To install with composer run the following command:

$ composer require slam/flysystem-compress-and-encrypt-proxy

Usage

use SlamCompressAndEncryptProxy\CompressAdapter;
use SlamCompressAndEncryptProxy\EncryptAdapter;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;

// Create a strong key and save it somewhere
$key = EncryptAdapter::generateKey();

// Create the final FilesystemAdapter, for example Aws S3
$remoteAdapter = new AwsS3V3Adapter(/* ... */);

$adapter = new CompressAdapter(new EncryptAdapter(
    $remoteAdapter,
    $key
));

// The FilesystemOperator
$filesystem = new \League\Flysystem\Filesystem($adapter);

// Upload a file, with stream
$handle = fopen('my-huge-file.txt', 'r');
$filesystem->writeStream('data.txt', $handle);
fclose($handle);

// Remotely a data.txt.gz.encrypted file has now been created

// Download a file, with stream
$handle = $filesystem->readStream('data.txt');
file_put_contents('my-huge-file.txt', $handle);
fclose($handle);

Streams

Both write and read operations leverage streams to keep memory usage low.

A 10 Gb mysqldump output can be streamed into a 1 Gb dump.sql.gz.encrypted file with a 10 Mb RAM footprint of the running php process, and no additional local disk space required.

Compression

GZip's zlib.deflate and zlib.inflate compression filters are used.

You can opt-out compression by using just the EncryptAdapter.

Encryption

Sodium extension provides the backend for the encrypted stream with XChaCha20-Poly1305 algorithm.

Caveats

MIME types detection

Some Flysystem adapters like the Local one try to guess the file mime type by its nature (content or extension): in such cases it will fail due to the custom extention and the encrypted content. Other adapters like the Aws S3 one allow you to specify it manually (for ex. with the ContentType key in the Config): it is a good idea to always manually inject it, if you like the Filesystem::mimeType($path) call to be reliable.

File size

The file size returned relates to the compressed and encrypted file, not the original one.

You might also like...
PHP runtime & extensions header files for PhpStorm

phpstorm-stubs STUBS are normal, syntactically correct PHP files that contain function & class signatures, constant definitions, etc. for all built-in

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build parse trees and also generates a listener interface (or visitor) that makes it easy to respond to the recognition of phrases of interest.

Tailwind plugin to generate purge-safe.txt files
Tailwind plugin to generate purge-safe.txt files

Tailwind plugin to generate safelist.txt files With tailwind-safelist-generator, you can generate a safelist.txt file for your theme based on a set of

Associate files with Eloquent models
Associate files with Eloquent models

Associate files with Eloquent models This package can associate all sorts of files with Eloquent models. It provides a simple API to work with. To lea

This package used to upload files using laravel-media-library before saving model.
This package used to upload files using laravel-media-library before saving model.

Laravel Media Uploader This package used to upload files using laravel-media-library before saving model. In this package all uploaded media will be p

A python program to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks.

I'm writing a python script to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks called ReCut. So far there are two

FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

Private file storage and share with user build with laravel and vue inspired by google drive
Private file storage and share with user build with laravel and vue inspired by google drive

LaravelDrive is a file storage system that allows store private file and share with users build wiht laravel and vue inspired by google drive. Laravel

Releases(v0.5.1)
  • v0.5.1(Dec 7, 2021)

    What's Changed

    • stream_filter_append: configure STREAM_FILTER_READ as is the only method used by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/16
    • Update to flysystem:2.3.2 by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/17

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.5.0...v0.5.1

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Nov 19, 2021)

    What's Changed

    • Gzip: use native deflate|inflate functions by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/13
    • V1Encrypt: filename must match adapter name by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/14
    • Add Zip proxy adapter by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/15

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.4.0...v0.5.0

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Nov 17, 2021)

    What's Changed

    • README: explain multipack by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/11
    • Move to SlamFlysystem namespace by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/12

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.3.0...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Nov 17, 2021)

    What's Changed

    • GZip: produce files compatible with gzip binary by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/6
    • Proxy adapter: list only files with own extension by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/7
    • Fix CRC32 check on real files by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/8
    • GzipAdapter: use GzipStreamFilter by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/9
    • Monorepo - Multipack by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/10

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.2.2...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.2(Nov 10, 2021)

    What's Changed

    • Test against PHP 8.1 by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/5
    • Always close streams opened internally by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/commit/0e06b2a38abbfb9852bf54f4b15c6fcb311a81d2

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.2.1...v0.2.2

    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Nov 8, 2021)

    What's Changed

    • Split Compression from Encryption to allow encryption-only by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/4

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.2.0...v0.2.1

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 7, 2021)

    BC break

    • Mark stream end to detect file truncation by @Slamdunk in https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/pull/3

    Full Changelog: https://github.com/Slamdunk/flysystem-compress-and-encrypt-proxy/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Nov 5, 2021)

Owner
Filippo Tessarotto
Filippo Tessarotto
Flysystem adapter for Google Cloud Storage

Flysystem adapter for Google Cloud Storage This package contains a Google Cloud Storage driver for Flysystem. Notice This package is a fork from super

Spatie 21 May 1, 2022
Flysystem V2 adapter for the webman

Flysystem V2 adapter for the webman

null 0 Nov 3, 2021
Microsoft OneDrive adapter for Flysystem 2+

Lexik Flysystem OneDrive Adapter This is a Flysystem 2+ adapter to interact with Microsoft OneDrive API. Setup In your Microsoft Azure portal create a

Choosit 3 Nov 19, 2021
💾 Flysystem adapter for the GitHub storage.

Flysystem Github Requirement PHP >= 7.2 CDN List 'github' => "https://raw.githubusercontent.com/:username/:repository/:branch/:fullfilename", 'fastg

wangzhiqiang 2 Mar 18, 2022
PHP stream wrapper for Flysystem v2

Flystream enables you to use core PHP filesystem functions to interact with Flysystem filesystems by registering them as custom protocols.

Matthew Turland 12 Dec 14, 2022
A stream wrapper for Flysystem V2.

Flysystem Stream Wrapper This package provides a stream wrapper for Flysystem V2. Flysystem V1 If you're looking for Flysystem 1.x support, check out

Martin Mandl 9 Oct 21, 2022
This small PHP package assists in the loading and parsing of VTT files.

VTT Transcriptions This small PHP package assists in the loading and parsing of VTT files. Usage use Laracasts\Transcriptions\Transcription; $transcr

Laracasts 52 Nov 28, 2022
FileGator - a free, open-source, self-hosted web application for managing files and folders.

FileGator - Powerful Multi-User File Manager FileGator is a free, open-source, self-hosted web application for managing files and folders. You can man

FileGator 1.3k Jan 3, 2023
PHP library that provides a filesystem abstraction layer − will be a feast for your files!

Gaufrette Gaufrette provides a filesystem abstraction layer. Why use Gaufrette? Imagine you have to manage a lot of medias in a PHP project. Lets see

KNP Labs 2.4k Jan 7, 2023