Giter VIP home page Giter VIP logo

flysystem-hash's Introduction

Flysystem Plugin for generating hash value of file

build Software License Packagist Version

NOTE: Plugins were removed in Flysystem 2.0 and thus this library is only available for Flysystem 1.x.

A plugin for the Flysystem file system abstraction library to generate hash values of a file. See hash_algos() function for supported hash algorithms.

Tested with Local and WebDav adapters, but as the hash is built directly from the stream resource it should work for all other adapters as well.

Installation

composer require emgag/flysystem-hash

Usage

use Emgag\Flysystem\Hash\HashPlugin;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem; 

$fs = new Filesystem(new Local(__DIR__));
$fs->addPlugin(new HashPlugin);

// sha256 is default
$sha256 = $fs->hash('file.txt');
$sha256 = $fs->hash('file.txt', 'sha256');
$md5    = $fs->hash('file.txt', 'md5');
$sha1   = $fs->hash('file.txt', 'sha1');

License

flysystem-hash is licensed under the MIT License.

flysystem-hash's People

Contributors

maetthu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

royalwang

flysystem-hash's Issues

Consider S3 md5 without streaming bytes

For your consideration.

When the adapter is S3 and the request checksum 'md5' the following snippets should work without downloading the actual bytes as S3 calculates an MD5 hash to be used as ETAG.

(from deep within our code)

private function getChecksum(AdapterInterface $adapter, string $path): ?string
    {
        switch (true) {
            case $adapter instanceof AwsS3Adapter:

                /** @var \Aws\Result $result */
                $result = $adapter->getClient()->headObject([
                    'Bucket' => $adapter->getBucket(),
                    'Key' => \trim($adapter->getPathPrefix(), '/') . $path,
                ]);

                return \trim($result->get('ETag'), '"');
                break;
            default:
                return null;
        }
    }

cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.