Skip to content

coderaiser/domfs-philip

Repository files navigation

Philip

Dom File System processing library

Install

npm i philip

How to use?

<script src="dist/philip.js"></script>

When used with webpack:

import philip from 'philip';
window.addEventListener('drop', (e) => {
    e.preventDefault();
    
    const [item] = e.dataTransfer.items;
    const entry = item.webkitGetAsEntry();
    
    const upload = philip(entry, (type, name, data /*, i, n,*/, callback) => {
        const error = null;
        
        switch(type) {
        case 'file':
            console.log('file', name, data);
            break;
        
        case 'directory':
            console.log('directory', name);
            break;
        }
        
        callback();
    });
    
    upload.on('error', (error) => {
        upload.abort();
        console.error(error);
    });
    
    upload.on('progress', (count) => {
        console.log(count);
    });
    
    upload.on('end', () => {
        console.log('done');
    });
});

window.addEventListener('dragover', (e) => {
    e.preventDefault();
});

License

MIT