Skip to Content
Using the HTML5 Filesystem API
book

Using the HTML5 Filesystem API

by Eric Bidelman
July 2011
Intermediate to advanced
72 pages
1h 13m
English
O'Reilly Media, Inc.
Content preview from Using the HTML5 Filesystem API

Chapter 8. The Synchronous API

Introduction

The HTML5 Filesystem API includes a synchronous version that, for the most part, is exactly the same as its asynchronous cousin. The methods, properties, features, and functionality will be familiar. The major deviations are:

  • The synchronous API can only be used within a Web Worker context. The asynchronous API can be used in and out of a worker.

  • Callbacks are out. API methods now return values.

  • The global methods on the window object (requestFileSystem() and resolveLocalFileSystemURL()) are renamed as requestFileSystemSync() and resolveLocalFileSystemSyncURL() and members of the worker’s global scope.

The two APIs are the same, save these few exceptions. Because there is not much new to cover, this chapter won’t cover the synchronous API in great detail. I’ll only highlight the exceptions to the asynchronous API and provide a few examples to make things clear.

Opening a Filesystem

A web application obtains access to the synchronous filesystem by requesting a LocalFileSystemSync object from within a web worker. The requestFileSystemSync() is exposed to the worker’s global scope:

var fs = requestFileSystemSync(TEMPORARY, 1024*1024 /*1MB*/);

Warning

This method is currently vendor prefixed as webkitRequestFileSystemSync.

The reader should note two things about this call: the new return value and the absence of success and error callbacks.

Working with Files and Directories

The synchronous filesystem has a getFile() and getDirectory() which return a ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5 Geolocation

HTML5 Geolocation

Anthony T. Holdener
HTML5 Hacks

HTML5 Hacks

Jesse Cravens, Jeff Burtoft
HTML5 Unleashed

HTML5 Unleashed

Simon Sarris

Publisher Resources

ISBN: 9781449311384Errata Page