
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
view-binary-element
Advanced tools
Native Web Component for previewing a few common types of binary files
Native Web Component for previewing a few common types of binary files
This is essentially a refactored version of https://github.com/grtjn/view-file-ng to eliminate AngularJS. Not yet as feature rich though.
Disclaimer: Work in Progress, and not tested in production. Feedback welcome though.
Check https://caniuse.com/ to verify how well Web Components is covered by current browsers. This component uses Custom Elements v1, (optionally) HTML Imports, HTML Templates, Shadow DOM v1 (gracefull decay would be possible).
Simplest way:
<link rel="import" href="https://cdn.rawgit.com/grtjn/view-binary-element/master/view-binary.html">
Likely together with this polyfill:
<script src="https://cdn.rawgit.com/webcomponents/webcomponentsjs/v1.2.0/webcomponents-hi.js" type="text/javascript" defer></script>
This component is also published on npm:
npm install --save view-binary-element
Potentially combined with something like:
<%= require('html-loader!../node_modules/view-binary-element/view-binary.html') %>
This component is also published on bower:
bower install --save view-binary-element
You can combine that with gulp and wiredep with something like:
.pipe(gulpWiredep({
fileTypes: {
html: {
block: /(([ \t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
detect: {
js: /<script.*src=['"]([^'"]+)/gi,
css: /<link.*href=['"]([^'"]+)/gi,
html: /<link.*href=['"]([^'"]+)/gi
},
replace: {
js: '<script src="{{filePath}}"></script>',
css: '<link rel="stylesheet" href="{{filePath}}">',
html: '<link rel="import" href="{{filePath}}">'
}
}
}
}))
Add this to your index.html:
<!-- bower:html -->
<link rel="import" href="/bower_components/view-binary-element/view-binary.html">
<!-- endbower -->
<!-- @exclude -->
<script src="https://cdn.rawgit.com/webcomponents/webcomponentsjs/v1.2.0/webcomponents-hi.js" type="text/javascript" defer></script>
<!-- @endexclude -->
This relies on the html-import polyfill loaded from CDN. If you prefer not to rely on that, or if your tooling builds minified versions of everything, you can include the html similarly to html-loader mentioned above in NPM, and strip off the polyfill using gulp-preprocessor roughly like this:
.pipe(gulpReplace(/<link rel="import" href="([^"]+)">/g, '<!-- @include ../$1 -->'))
.pipe(gulpPreprocess())
Example:
<view-binary class="audio" src="data/sample-music.mp3" type="audio/mpeg" title="sample-music.mp3">
<a slot="fallback" href="data/sample-music.mp3" target="_blank" download>Download sample-music.mp3</a>
</view-binary>
Does not emit events.
Assumes CDN and polyfill installation
In your html:
<style>
view-binary {
display: block;
height: 300px;
}
view-binary.audio {
height: 32px;
}
</style>
<view-binary class="audio" src="data/sample-music.mp3" type="audio/mpeg" title="sample-music.mp3">
<a slot="fallback" href="data/sample-music.mp3" target="_blank" download>Download sample-music.mp3</a>
</view-binary>
Import or include the web component in your index.html (see for instance NPM and html-loader installation)
Add view-binary to ignoreElements to stop it from squeaking:
Vue.config.ignoredElements = ["view-binary"];
Use it in any component:
<view-binary :src="viewUri" :type="contentType" :title="fileName">
<a slot="fallback" class="btn btn-default" :href="downloadUri" target="_blank" download>Download {{ fileName }}</a>
</view-binary>
Assumes Bower, wiredep, and gulp installation
In your html template:
<view-binary src="{{viewUri}}" type="{{contentType}}" title="{{fileName}}">
<a slot="fallback" class="btn btn-default" href="{{downloadUri}}" target="_blank" download>Download {{ fileName }}</a>
</view-binary>
python -m SimpleHTTPServer 8888 from project rootFAQs
Native Web Component for previewing a few common types of binary files
The npm package view-binary-element receives a total of 13 weekly downloads. As such, view-binary-element popularity was classified as not popular.
We found that view-binary-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.